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

Uploaded Python 3

File details

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

File metadata

  • Download URL: typemapping-0.1.3.tar.gz
  • Upload date:
  • Size: 37.8 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.3.tar.gz
Algorithm Hash digest
SHA256 5c0c6de8fa06c5c6a36f7e6ad05217afcd5041115f5a86e31e19ce3fc03fcdb9
MD5 e1ad8f8d7b032b95cd640bd30b3d9bc6
BLAKE2b-256 0206b256faddea43ea27806134b6eaebc7450445cc0fbbd099fded79d213ac6b

See more details on using hashes here.

File details

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

File metadata

  • Download URL: typemapping-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 21.7 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.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d16f4e2bc0b0f4ceb19a3e25b79232161d4c4f9b81b623c4274eb5e966caeed3
MD5 7be43e2ad2df17fb72a0c1d20693e49f
BLAKE2b-256 c7792046c9d116bdf490e59359a6f7a3773b75caee4886e42bf8c73c2e025cbd

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