Skip to main content

Advanced type compatibility and checking system for Python

Project description

🧬 typemapping

Advanced Type Compatibility and Runtime Checking for Python 3.8+

typemapping is a powerful and extensible package for deep type introspection and runtime type validation. It goes far beyond Python's built-in isinstance and issubclass, supporting generic types, Annotated, Union, specialized collections, and more — with compatibility across Python 3.8+ including typing_extensions support.


🚀 Features

  • ✅ Generic type compatibility (List[int] ~ Sequence[int])
  • 🧠 Concrete-to-abstract compatibility (Counter, OrderedDict, ChainMap)
  • 🔁 Full Union and Optional type support
  • 🛠️ Python 3.8+ Annotated compatibility layer
  • 🧪 Runtime type validation with container sampling
  • 🔍 Field and function argument mapping with Annotated metadata extraction
  • 📦 Framework-friendly: works with FastAPI, Pydantic, SQLAlchemy, etc.

📦 Installation

pip install typemapping

⚠️ typing_extensions is required for full support on Python 3.8.


🧑‍💻 Example

from typing import List, Annotated
from typemapping.type_check import extended_isinstance

# Check generic type compatibility
print(extended_isinstance([1, 2, 3], List[int]))  # True
print(extended_isinstance([1, 2, 3], List[str]))  # False

🧩 Key APIs

🔎 Type Checking & Compatibility

  • extended_isinstance(obj, type_hint)
  • generic_issubclass(subtype, supertype)
  • is_equal_type(t1, t2)
  • defensive_issubclass(cls, classinfo)

🧬 Annotated Type Handling

  • is_annotated_type(type)
  • strip_annotated(type)
  • get_annotated_metadata(type)

🧠 Function and Class Introspection

  • get_func_args(func)
  • map_model_fields(cls)
  • map_dataclass_fields(cls)
  • get_field_type(cls, fieldname)

🔁 Origin Compatibility

  • is_equivalent_origin(t1, t2)
  • get_equivalent_origin(t)
  • is_fully_compatible(t1, t2)
  • get_compatibility_chain(t)

⚙️ Compatibility

  • ✅ Python 3.8 and above
  • 🔄 Backward-compatible via typing_extensions

🧪 Running Tests

pytest

📄 License

MIT License


🤝 Contributing

Contributions are welcome! Feel free to open issues or submit pull requests.

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

typemapping-0.1.4.tar.gz (38.5 kB view details)

Uploaded Source

Built Distribution

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

typemapping-0.1.4-py3-none-any.whl (21.8 kB view details)

Uploaded Python 3

File details

Details for the file typemapping-0.1.4.tar.gz.

File metadata

  • Download URL: typemapping-0.1.4.tar.gz
  • Upload date:
  • Size: 38.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for typemapping-0.1.4.tar.gz
Algorithm Hash digest
SHA256 ba8d36d2d0b16a88bae61de92dc42d5d25e7c1860978e9eea1435382c2adfb42
MD5 76474dafab4488b52457a02ad434ad67
BLAKE2b-256 d8efc10dc0a36947fd06aade3c7f1b86776f7609832b8e067d5817387df98797

See more details on using hashes here.

File details

Details for the file typemapping-0.1.4-py3-none-any.whl.

File metadata

  • Download URL: typemapping-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 21.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.12.1

File hashes

Hashes for typemapping-0.1.4-py3-none-any.whl
Algorithm Hash digest
SHA256 765cc9e50ed7d143e132161c7eae32d2d5d264a5d9bc2b54a77e63998c2c20c1
MD5 4acf4dae353d53760d62b4dad0ee0438
BLAKE2b-256 aeee3dfb7b3dbfe800416a4551780956290c7441ed87e358e43c6c5b16d95570

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 Pingdom Monitoring Sentry Error logging StatusPage Status page