{"id":4831,"library":"typing-utils","title":"Typing Utils","description":"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.","status":"maintenance","version":"0.1.0","language":"en","source_language":"en","source_url":"https://github.com/bojiang/typing_utils","tags":["typing","type hints","reflection","metaprogramming","type checking"],"install":[{"cmd":"pip install typing-utils","lang":"bash","label":"Install with pip"}],"dependencies":[],"imports":[{"symbol":"issubtype","correct":"from typing_utils import issubtype"},{"symbol":"get_origin","correct":"from typing_utils import get_origin"},{"symbol":"get_args","correct":"from typing_utils import get_args"},{"symbol":"get_type_hints","correct":"from typing_utils import get_type_hints"}],"quickstart":{"code":"import typing\nfrom typing_utils import issubtype, get_origin, get_args\n\n# Using issubtype\nassert issubtype(list, typing.Sequence) == True\nassert issubtype(typing.List[int], list) == True\nassert issubtype(list, typing.List[int]) == False\n\n# Using get_origin\nassert get_origin(typing.List[int]) == list\nassert get_origin(list) == list\n\n# Using get_args\nassert get_args(typing.List[int]) == (int,)\nassert get_args(typing.Dict[str, float]) == (str, float)\n\nprint(\"Typing utilities working correctly!\")","lang":"python","description":"This quickstart demonstrates the core functionality of `typing-utils` by checking subtype relationships and extracting origin and arguments from type annotations."},"warnings":[{"fix":"Review type comparison logic if upgrading from versions prior to 0.1.0 to ensure intended behavior, especially for complex or union types.","message":"The 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.","severity":"breaking","affected_versions":"<0.1.0"},{"fix":"Carefully consult the official documentation for `get_type_hints` when using `globalns` and `localns` to understand their scope and interaction with forward references.","message":"The `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.","severity":"gotcha","affected_versions":"All"},{"fix":"For new code and when refactoring, prefer native type hints like `list[str]` over `typing.List[str]` when defining your type annotations.","message":"Starting 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.","severity":"deprecated","affected_versions":"Python 3.9+"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}