Registry / type-stubs / typing-utils

typing-utils

JSON →
library0.1.0pypypi✓ verified 21d ago

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.

pip install typing-utils
INSTALL
IMPORT
SIG · TYPING-UTILS
T
typing-utils
type-stubspythonv0.1.0
Install
1.6s avg
Import
11ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.012s · 17.8MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.008s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

issubtype
from typing_utils import issubtype
get_origin
from typing_utils import get_origin
get_args
from typing_utils import get_args
get_type_hints
from typing_utils import get_type_hints

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!")
Debug
Known issues
breakingThe 0.1.0 release introduced several fixes and behavior changes for `issubtype`, particularly concerning `Union`, `None` (as `type(None)`), `TypeVar` checking, and `Callable`. Users upgrading from pre-0.1.0 versions might observe different results for type comparisons that previously exhibited buggy behavior.
fix
Review type comparison logic if upgrading from versions prior to 0.1.0 to ensure intended behavior, especially for complex or union types.
affects: <0.1.0
gotchaThe `get_type_hints` function, while powerful, has 'counterintuitive' behavior regarding its `globalns` and `localns` parameters, similar to how `eval()` and `exec()` work. Incorrect usage can lead to unexpected results, especially with forward references.
fix
Carefully consult the official documentation for `get_type_hints` when using `globalns` and `localns` to understand their scope and interaction with forward references.
affects: All
deprecatedStarting with Python 3.9, many common types from the standard `typing` module (e.g., `List`, `Dict`, `Set`, `Tuple`) are deprecated in favor of using native collection types directly (e.g., `list[str]`, `dict[str, int]`). While `typing-utils` can inspect these types, relying on the deprecated `typing` forms in your codebase might lead to linting warnings or compatibility issues with future Python versions or type checkers.
fix
For new code and when refactoring, prefer native type hints like `list[str]` over `typing.List[str]` when defining your type annotations.
affects: Python 3.9+
Upgrade
Version history
0.1.0latest on PyPI · released May 23, 2021
Audit
Dependencies

No dependency data recorded yet.

Agent activity
31 hits · last 30 days
node
26
OpenAI (training)
1
Resources
typing-utils — pip install typing-utils · libregistry