typing-inspect is a Python library providing runtime inspection utilities for types defined in the standard `typing` module. It is currently at version 0.9.0, is actively maintained, and compatible with Python 3.6 and later. It offers an easy-to-use API for advanced introspection of type hints.
pip install typing-inspectVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates basic usage of `typing-inspect` to check for generic types, retrieve type arguments and origins, and identify optional types. It covers `is_generic_type`, `get_args`, `get_origin`, and `is_optional_type`.
Always pin the `typing-inspect` version in your `requirements.txt` or `pyproject.toml` to ensure consistent behavior across deployments.
Double-check your `pip install` command (`pip install typing-inspect`) and import statements (`import typing_inspect` or `from typing_inspect import ...`) to ensure you are using the correct package.
Avoid using `get_args(tp, evaluate=True)` in performance-critical paths unless strictly necessary. The default `evaluate=False` reports results as nested tuples and is generally more performant.
Ensure your project's `typing` and `typing-extensions` dependencies are up-to-date or meet the minimum versions specified by `typing-inspect` (currently `typing>=3.7.4` and `typing-extensions>=3.7.4`).