type-analyzer
Functions for introspecting Python type hints.
Installation
⚠️ Requires Python 3.12 or higher
pip install type-analyzer
Usage
matching_types
matching_types returns every type a type hint matches, without duplicates. Unions
are unpacked into their members, and Annotated metadata is removed:
from typing import Annotated
from type_analyzer import matching_types
matching_types(str | int)
# => (str, int)
matching_types(Annotated[str, "metadata"] | None)
# => (str, NoneType)
matching_types(list[Annotated[int, "metadata"]])
# => (list[int],)
Options
MatchingTypesConfig adds more types to the result. Every option is disabled by
default:
| Option | Effect |
|---|---|
ignore_none |
Leaves out None. |
with_bases |
Adds the base classes, with their type arguments. |
with_origin |
Adds the origin of generic types (list[str] → list). |
with_type_alias_value |
Adds the value of type aliases. |
from type_analyzer import MatchingTypesConfig, matching_types
# ----- ignore_none -----
config = MatchingTypesConfig(ignore_none=True)
matching_types(str | None, config)
# => (str,)
# ----- with_bases -----
class A[T]: ...
class B[T]: ...
class C[T1, T2](A[T1], B[T2]): ...
config = MatchingTypesConfig(with_bases=True)
matching_types(C[str, int], config)
# => (C[str, int], A[str], B[int])
# ----- with_origin -----
config = MatchingTypesConfig(with_origin=True)
matching_types(list[str], config)
# => (list[str], list)
# ----- with_type_alias_value -----
type StringOr[T] = str | T
config = MatchingTypesConfig(with_type_alias_value=True)
matching_types(StringOr[int], config)
# => (StringOr[int], str, int)
Options can be combined: MatchingTypesConfig(with_bases=True, with_origin=True).
iter_matching_types
iter_matching_types is the lazy counterpart of matching_types: it yields the
types one by one, and keeps the duplicates.
from type_analyzer import MatchingTypesConfig, iter_matching_types
class Left: ...
class Right: ...
class Both(Left, Right): ...
config = MatchingTypesConfig(with_bases=True)
list(iter_matching_types(Both, config))
# => [Both, Left, object, Right, object]
Metadata
Release files for type-analyzer 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| type_analyzer-0.2.0.tar.gz | 6.9 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| type_analyzer-0.2.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 11.7 kB
Release files / type_analyzer-0.2.0.tar.gz
| Download URL | type_analyzer-0.2.0.tar.gz |
|---|---|
| Size | 6.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
d6bed633d7de62e7627619f0f6dc057fda5404a95d2ee2c1ffb6ef5295958f46
|
|
BLAKE2b-256 checksum How to use checksums |
83662c019b4a3ec0b9ba1703a2156227ab052c262232d78c99f078a3c3177959
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Release files / type_analyzer-0.2.0-py3-none-any.whl
| Download URL | type_analyzer-0.2.0-py3-none-any.whl |
|---|---|
| Size | 4.8 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
654d373d1542c12389d43f5e0ce830bebcf8c041070c5c124b70f3851c130ebf
|
|
BLAKE2b-256 checksum How to use checksums |
791976badd92b1688b1afa0c6178fb397f42723a1c83f01d3b473fb6d816f685
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.13.5 {"installer":{"name":"uv","version":"0.13.5","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}
|
Security for type-analyzer 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.