typemapping


Nametypemapping JSON
Version 0.1.5 PyPI version JSON
download
home_pageNone
SummaryAdvanced type compatibility and checking system for Python
upload_time2025-07-31 17:47:44
maintainerNone
docs_urlNone
authorNone
requires_python>=3.8
licenseMIT
keywords typing type-checking generics variance annotations
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # ๐Ÿงฌ 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

```bash
pip install typemapping
```

> โš ๏ธ `typing_extensions` is required for full support on Python 3.8.

---

## ๐Ÿง‘โ€๐Ÿ’ป Example

```python
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

```bash
pytest
```

---

## ๐Ÿ“„ License

MIT License

---

## ๐Ÿค Contributing

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "typemapping",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "typing, type-checking, generics, variance, annotations",
    "author": null,
    "author_email": "rodbell <bellirodrigo2@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/68/36/7e62d8f27e85b920a1788d1150a5dc1e7fc68c7cff164e9a48239d517fb8/typemapping-0.1.5.tar.gz",
    "platform": null,
    "description": "# \ud83e\uddec typemapping\r\n\r\n**Advanced Type Compatibility and Runtime Checking for Python 3.8+**\r\n\r\n`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 \u2014 with compatibility across Python 3.8+ including `typing_extensions` support.\r\n\r\n---\r\n\r\n## \ud83d\ude80 Features\r\n\r\n* \u2705 Generic type compatibility (`List[int] ~ Sequence[int]`)\r\n* \ud83e\udde0 Concrete-to-abstract compatibility (`Counter`, `OrderedDict`, `ChainMap`)\r\n* \ud83d\udd01 Full `Union` and `Optional` type support\r\n* \ud83d\udee0\ufe0f Python 3.8+ `Annotated` compatibility layer\r\n* \ud83e\uddea Runtime type validation with container sampling\r\n* \ud83d\udd0d Field and function argument mapping with `Annotated` metadata extraction\r\n* \ud83d\udce6 Framework-friendly: works with FastAPI, Pydantic, SQLAlchemy, etc.\r\n\r\n---\r\n\r\n## \ud83d\udce6 Installation\r\n\r\n```bash\r\npip install typemapping\r\n```\r\n\r\n> \u26a0\ufe0f `typing_extensions` is required for full support on Python 3.8.\r\n\r\n---\r\n\r\n## \ud83e\uddd1\u200d\ud83d\udcbb Example\r\n\r\n```python\r\nfrom typing import List, Annotated\r\nfrom typemapping.type_check import extended_isinstance\r\n\r\n# Check generic type compatibility\r\nprint(extended_isinstance([1, 2, 3], List[int]))  # True\r\nprint(extended_isinstance([1, 2, 3], List[str]))  # False\r\n```\r\n\r\n---\r\n\r\n## \ud83e\udde9 Key APIs\r\n\r\n### \ud83d\udd0e Type Checking & Compatibility\r\n\r\n* `extended_isinstance(obj, type_hint)`\r\n* `generic_issubclass(subtype, supertype)`\r\n* `is_equal_type(t1, t2)`\r\n* `defensive_issubclass(cls, classinfo)`\r\n\r\n### \ud83e\uddec Annotated Type Handling\r\n\r\n* `is_annotated_type(type)`\r\n* `strip_annotated(type)`\r\n* `get_annotated_metadata(type)`\r\n\r\n### \ud83e\udde0 Function and Class Introspection\r\n\r\n* `get_func_args(func)`\r\n* `map_model_fields(cls)`\r\n* `map_dataclass_fields(cls)`\r\n* `get_field_type(cls, fieldname)`\r\n\r\n### \ud83d\udd01 Origin Compatibility\r\n\r\n* `is_equivalent_origin(t1, t2)`\r\n* `get_equivalent_origin(t)`\r\n* `is_fully_compatible(t1, t2)`\r\n* `get_compatibility_chain(t)`\r\n\r\n---\r\n\r\n## \u2699\ufe0f Compatibility\r\n\r\n* \u2705 Python 3.8 and above\r\n* \ud83d\udd04 Backward-compatible via `typing_extensions`\r\n\r\n---\r\n\r\n## \ud83e\uddea Running Tests\r\n\r\n```bash\r\npytest\r\n```\r\n\r\n---\r\n\r\n## \ud83d\udcc4 License\r\n\r\nMIT License\r\n\r\n---\r\n\r\n## \ud83e\udd1d Contributing\r\n\r\nContributions are welcome! Feel free to open issues or submit pull requests.\r\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Advanced type compatibility and checking system for Python",
    "version": "0.1.5",
    "project_urls": null,
    "split_keywords": [
        "typing",
        " type-checking",
        " generics",
        " variance",
        " annotations"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "97c20b5711e51922bf25ef81b59e606a2f61b979a740aab1a4dcaad249545727",
                "md5": "0384bb13b62a6f60f6a46c8eae1ade92",
                "sha256": "a304d67db6943107a4603969c209e3874c20f5a50bfbbc383595314299717c5c"
            },
            "downloads": -1,
            "filename": "typemapping-0.1.5-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0384bb13b62a6f60f6a46c8eae1ade92",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 22627,
            "upload_time": "2025-07-31T17:47:43",
            "upload_time_iso_8601": "2025-07-31T17:47:43.199842Z",
            "url": "https://files.pythonhosted.org/packages/97/c2/0b5711e51922bf25ef81b59e606a2f61b979a740aab1a4dcaad249545727/typemapping-0.1.5-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "68367e62d8f27e85b920a1788d1150a5dc1e7fc68c7cff164e9a48239d517fb8",
                "md5": "6c1ef2479b79d3eb375d81e3b644da21",
                "sha256": "55e131399b065491e9d687ca1c9ecd631e7a9997fc93225d4a5a2a574070f362"
            },
            "downloads": -1,
            "filename": "typemapping-0.1.5.tar.gz",
            "has_sig": false,
            "md5_digest": "6c1ef2479b79d3eb375d81e3b644da21",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 43802,
            "upload_time": "2025-07-31T17:47:44",
            "upload_time_iso_8601": "2025-07-31T17:47:44.681363Z",
            "url": "https://files.pythonhosted.org/packages/68/36/7e62d8f27e85b920a1788d1150a5dc1e7fc68c7cff164e9a48239d517fb8/typemapping-0.1.5.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-31 17:47:44",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "typemapping"
}
        
Elapsed time: 0.66915s