Skip to main content

Utilities for generic type inspection in Python.

Project description

generic-inspection

Utilities for generic type inspection. Supports Python 3.10+.

Inferring specialised type arguments

Consider the following code:

from typing import Generic, TypeVar

InputT = TypeVar("InputT")
OutputT = TypeVar("OutputT")

class Machine(Generic[InputT, OutputT]):
    pass

class TextMachine(Machine[InputT, str]):
    pass

class NumberTextMachine(TextMachine[float]):
    pass

We can infer the specialised type arguments of a subclass with respect to the class type parameters of a particular base class using the infer_generic_args function.

>>> from generic_inspection import infer_generic_args
>>> infer_generic_args(Machine, NumberTextMachine)
(<class 'float'>, <class 'str'>)

The results here tell us that InputT is float and OutputT is str.

Development environment

# Set up the virtual environment.
uv sync --frozen --all-groups
# Run tests.
just test

Release process

The release process is automatic after pushing a semver tag to main.

# Ensure that the correct version number is in pyproject.toml.
head pyproject.toml
# Create the tag.
git tag -a v0.1.0 -m "Release v0.1.0"
# Push the tag.
git push --tags
# Check GitHub Actions and PyPI to verify successful publication.

Similar projects

License

Copyright 2026 Aiden Nibali

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

    http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.

Project details


Download files

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

Source Distribution

generic_inspection-0.1.0.tar.gz (8.2 kB view details)

Uploaded Source

Built Distribution

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

generic_inspection-0.1.0-py3-none-any.whl (9.5 kB view details)

Uploaded Python 3

File details

Details for the file generic_inspection-0.1.0.tar.gz.

File metadata

  • Download URL: generic_inspection-0.1.0.tar.gz
  • Upload date:
  • Size: 8.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for generic_inspection-0.1.0.tar.gz
Algorithm Hash digest
SHA256 e807270771814a9b853d2a6ba6e2a317a0c0931daceb549c93bf72d16d8d7765
MD5 7e7e09a085e19ab568cc91389dfce768
BLAKE2b-256 718bccf5de66cbd78737bc7750288d663daaafd9b7d1045cb59a596fe58a2ac7

See more details on using hashes here.

Provenance

The following attestation bundles were made for generic_inspection-0.1.0.tar.gz:

Publisher: release.yaml on anibali/generic-inspection

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file generic_inspection-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for generic_inspection-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 37d2a734ae05ccd1e096de204005914b6ce4341b4921858aa814744e89de6eea
MD5 9dc65e8e919f170dc93a579855e53962
BLAKE2b-256 bd04474ef960a781f30aa52c006a4f5a773e92161b5eb40f79ed341f948f1f42

See more details on using hashes here.

Provenance

The following attestation bundles were made for generic_inspection-0.1.0-py3-none-any.whl:

Publisher: release.yaml on anibali/generic-inspection

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

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