Typing Utils

0.1.0 · maintenance · verified Sun Apr 12

typing-utils is a Python library providing utilities to inspect Python type annotations. It backports features found in Python 3.8+ for type inspection, including `issubtype`, `get_origin`, `get_args`, and `get_type_hints`. The current version is 0.1.0, released in May 2021, suggesting a maintenance release cadence.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates the core functionality of `typing-utils` by checking subtype relationships and extracting origin and arguments from type annotations.

import typing
from typing_utils import issubtype, get_origin, get_args

# Using issubtype
assert issubtype(list, typing.Sequence) == True
assert issubtype(typing.List[int], list) == True
assert issubtype(list, typing.List[int]) == False

# Using get_origin
assert get_origin(typing.List[int]) == list
assert get_origin(list) == list

# Using get_args
assert get_args(typing.List[int]) == (int,)
assert get_args(typing.Dict[str, float]) == (str, float)

print("Typing utilities working correctly!")

view raw JSON →