Skip to main content

type-analyzer

PyPI - Version PyPI - Downloads GitHub Stars CI Ruff

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.post0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for type-analyzer 0.2.0.post0
File Size Uploaded Provenance Actions
type_analyzer-0.2.0.post0.tar.gz 6.9 kB Without provenance Details for type_analyzer-0.2.0.post0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for type-analyzer 0.2.0.post0
File Interpreter ABI Platform Actions
type_analyzer-0.2.0.post0-py3-none-any.whl Python 3 none any Details for type_analyzer-0.2.0.post0-py3-none-any.whl

Total release size: 11.8 kB

Release files / type_analyzer-0.2.0.post0.tar.gz

Download URL type_analyzer-0.2.0.post0.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
03881babdd2658f7652401b9d4ab9eff0ef43229c60ff84d9a8fa5a1a6116f18
BLAKE2b-256 checksum
How to use checksums
03fa09cc8f4682c35d02af104bc799ba9a0730ee6c8f3cd3dc90877b76edab0b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.post0-py3-none-any.whl

Download URL type_analyzer-0.2.0.post0-py3-none-any.whl
Size 4.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5c2654b6d29ee3d4389e46e2166ada97c4420d50e3c9d59cde4d959daef1b184
BLAKE2b-256 checksum
How to use checksums
76fadfd4bec5a9c2fb9f74aec7ae196cc31ed9c678923363647cbc8be44db1a3
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.13.8 {"installer":{"name":"uv","version":"0.13.8","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"26.04","id":"resolute","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.post0

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.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page