Skip to main content

typetoolbox

typetoolbox provides runtime utilities for inspecting Python generics and resolving TypeVar bindings.

Installation

uv add typetoolbox

Core APIs

  • GenericTypeMap: map TypeVar names to concrete runtime types for a generic class/alias.
  • get_generic_mapping(obj_or_type): build a GenericTypeMap from a class, alias, or object instance.
  • resolve_typevars(tp, mapping_source, strict=False): recursively resolve TypeVars in nested type expressions.
  • find_specializations(base_generic, where=None): find subclasses that fully close a base generic.
  • inspect_specializations(base_generic, include_generic=False, where=None): inspect subclasses with rich mapping metadata.
  • find_specializations_by_args(base_generic, args): return exact-arg specializations.
  • build_specialization_index(base_generic): map resolved arg tuples to implementations.
  • try_to_map_generic_args_to_specialization(generic_type, specialization_type): map generic args onto a concrete specialization.

Example

from typing import Generic, TypeVar

from typetoolbox import GenericTypeMap, find_specializations, resolve_typevars

X = TypeVar("X")
Y = TypeVar("Y")


class Pair(Generic[X, Y]):
    pass


class IntStrPair(Pair[int, str]):
    pass


mapping = GenericTypeMap(IntStrPair)
assert resolve_typevars(dict[X, list[Y]], mapping) == dict[int, list[str]]
assert find_specializations(Pair) == [IntStrPair]

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

typetoolbox-0.4.0.tar.gz (61.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

typetoolbox-0.4.0-py3-none-any.whl (11.4 kB view details)

Uploaded Python 3

File details

Details for the file typetoolbox-0.4.0.tar.gz.

File metadata

  • Download URL: typetoolbox-0.4.0.tar.gz
  • Upload date:
  • Size: 61.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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}

File hashes

Hashes for typetoolbox-0.4.0.tar.gz
Algorithm Hash digest
SHA256 2d72b2b24389e2d23ab8d1ba4132285493fc3884afd006950ba525fe9d3357c4
MD5 b34281fb6800376ff0686a8b11dfa4b9
BLAKE2b-256 ff259b1fbd56714cad55eac2ad541aa7e4eca621010f242defc1596b866d8b7e

See more details on using hashes here.

File details

Details for the file typetoolbox-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: typetoolbox-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 11.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.12.3 {"installer":{"name":"uv","version":"0.12.3","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}

File hashes

Hashes for typetoolbox-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 5435b992632535f519b55b9df6498cb1fd1e1b9e71b4120615c77c81cc3901e9
MD5 fa879b583ae564b5a9ca303ea2c744b2
BLAKE2b-256 3dc329efcdf05fcd70472fcee5b3c002834929ce2f5db1f6e5072dcbcd3cf650

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page