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.7.tar.gz (45.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.7-py3-none-any.whl (23.0 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: typemapping-0.1.7.tar.gz
  • Upload date:
  • Size: 45.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.7.tar.gz
Algorithm Hash digest
SHA256 cdaf1c3227846c69d502a802734af623516c4267741e44c3a2194e3bad331118
MD5 dca424f26225eb72a7a5a99a7547ee56
BLAKE2b-256 a1c6de89f810b88a071313b721c6d1751bf678873f6a608c4c62e9d0666036e6

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typemapping-0.1.7-py3-none-any.whl
  • Upload date:
  • Size: 23.0 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.7-py3-none-any.whl
Algorithm Hash digest
SHA256 f859eab64c407cc44f6a6c8d21667a643904d817e94e0a268154a1681927fe15
MD5 460b7549c3832d8eacf56bcb073cf9a2
BLAKE2b-256 870363f04dbf08bf5a898d7e2a3648e090ceebe9e780f168dba65e705164d0a4

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