typing-utilities


Nametyping-utilities JSON
Version 0.0.4 PyPI version JSON
download
home_pageNone
SummaryRuntime reflection and validation of types and generics.
upload_time2025-07-11 08:53:54
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseNone
keywords windows linux generics typing
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage
            [![Test](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test.yml/badge.svg)](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test.yml)
[![Coverage](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test-coverage.yml/badge.svg)](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test-coverage.yml)
[![Stable Version](https://img.shields.io/pypi/v/typing-utilities?label=stable&sort=semver&color=blue)](https://github.com/apmadsen/typing-utilities/releases)
![Pre-release Version](https://img.shields.io/github/v/release/apmadsen/typing-utilities?label=pre-release&include_prereleases&sort=semver&color=blue)
![PyPI - Python Version](https://img.shields.io/pypi/pyversions/typing-utilities)
[![PyPI Downloads](https://static.pepy.tech/badge/typing-utilities/week)](https://pepy.tech/projects/typing-utilities)

# typing-utilities: Runtime reflection and validation of types and generics.

typing-utilities extends Python with the ability to check instances and types of generic types and unions introduced in the `typing` module.

Following is a small example of two of the most usable functions `issubclass_typing` and `isinstance_typing`, but a lot more is to be found in the API section further down...

## Example:

```python
from typing import Generic, TypeVar
from typingutils import issubclass_typing, isinstance_typing

T = TypeVar('T')

class Class1(Generic[T]):
    pass

class_type1 = Class1[str]
class_type2 = Class1[int]

issubclass_typing(class_type1, class_type2) # => False

# next line will fail
issubclass(class_type1, class_type2) # => TypeErrorr: Subscripted generics cannot be used with class and instance checks

class_inst1 = class_type1()
class_inst2 = class_type2()

isinstance_typing(class_inst1, class_type1) # => True
isinstance_typing(class_inst1, class_type2) # => False
isinstance_typing(class_inst2, class_type2) # => True
isinstance_typing(class_inst2, class_type1) # => False

# next line will fail
isinstance(class_inst1, class_type1) # => TypeError: Subscripted generics cannot be used with class and instance checks
```

## Conventions

This project differs from Python and other projects in some aspects:

- Generic subscripted types like `list[str]` are always a subclass of its base type `list` whereas the opposite is not true.
- Any type is a subclass of `type[Any]`.
- `type[Any]` is not an instance of `type[Any]`.
- Builtin types and `typing` types are interchangeable, i.e. `list[T]` is interchangeable with `typing.List[T]` etc.

## What's not included

### Generic types

It's not the goal of this project to deliver generic types such as generically enforced lists and dicts.

## Full documentation

[Go to documentation](https://github.com/apmadsen/typing-utilities/blob/main/docs/documentation.md)

## Other similar projects

There are other similar projects out there like [typing-utils](https://pypi.org/project/typing-utils/) and [runtype](https://pypi.org/project/runtype/), and while typing-utils is outdated and pretty basic, runtype is very similar to `typing-utilities` when it comes to validation.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "typing-utilities",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": "windows, linux, generics, typing",
    "author": null,
    "author_email": "Anders Madsen <anders.madsen@alphavue.com>",
    "download_url": "https://files.pythonhosted.org/packages/61/b6/b257e8ad8550f990dc5eb4709be7a269f664a80fb76a36444d1965ef4337/typing_utilities-0.0.4.tar.gz",
    "platform": null,
    "description": "[![Test](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test.yml/badge.svg)](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test.yml)\n[![Coverage](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test-coverage.yml/badge.svg)](https://github.com/apmadsen/typing-utilities/actions/workflows/python-test-coverage.yml)\n[![Stable Version](https://img.shields.io/pypi/v/typing-utilities?label=stable&sort=semver&color=blue)](https://github.com/apmadsen/typing-utilities/releases)\n![Pre-release Version](https://img.shields.io/github/v/release/apmadsen/typing-utilities?label=pre-release&include_prereleases&sort=semver&color=blue)\n![PyPI - Python Version](https://img.shields.io/pypi/pyversions/typing-utilities)\n[![PyPI Downloads](https://static.pepy.tech/badge/typing-utilities/week)](https://pepy.tech/projects/typing-utilities)\n\n# typing-utilities: Runtime reflection and validation of types and generics.\n\ntyping-utilities extends Python with the ability to check instances and types of generic types and unions introduced in the `typing` module.\n\nFollowing is a small example of two of the most usable functions `issubclass_typing` and `isinstance_typing`, but a lot more is to be found in the API section further down...\n\n## Example:\n\n```python\nfrom typing import Generic, TypeVar\nfrom typingutils import issubclass_typing, isinstance_typing\n\nT = TypeVar('T')\n\nclass Class1(Generic[T]):\n    pass\n\nclass_type1 = Class1[str]\nclass_type2 = Class1[int]\n\nissubclass_typing(class_type1, class_type2) # => False\n\n# next line will fail\nissubclass(class_type1, class_type2) # => TypeErrorr: Subscripted generics cannot be used with class and instance checks\n\nclass_inst1 = class_type1()\nclass_inst2 = class_type2()\n\nisinstance_typing(class_inst1, class_type1) # => True\nisinstance_typing(class_inst1, class_type2) # => False\nisinstance_typing(class_inst2, class_type2) # => True\nisinstance_typing(class_inst2, class_type1) # => False\n\n# next line will fail\nisinstance(class_inst1, class_type1) # => TypeError: Subscripted generics cannot be used with class and instance checks\n```\n\n## Conventions\n\nThis project differs from Python and other projects in some aspects:\n\n- Generic subscripted types like `list[str]` are always a subclass of its base type `list` whereas the opposite is not true.\n- Any type is a subclass of `type[Any]`.\n- `type[Any]` is not an instance of `type[Any]`.\n- Builtin types and `typing` types are interchangeable, i.e. `list[T]` is interchangeable with `typing.List[T]` etc.\n\n## What's not included\n\n### Generic types\n\nIt's not the goal of this project to deliver generic types such as generically enforced lists and dicts.\n\n## Full documentation\n\n[Go to documentation](https://github.com/apmadsen/typing-utilities/blob/main/docs/documentation.md)\n\n## Other similar projects\n\nThere are other similar projects out there like [typing-utils](https://pypi.org/project/typing-utils/) and [runtype](https://pypi.org/project/runtype/), and while typing-utils is outdated and pretty basic, runtype is very similar to `typing-utilities` when it comes to validation.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Runtime reflection and validation of types and generics.",
    "version": "0.0.4",
    "project_urls": {
        "repository": "https://github.com/apmadsen/typing-utilities"
    },
    "split_keywords": [
        "windows",
        " linux",
        " generics",
        " typing"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "be7f6c33b2e385700fcd0540c3af4fe439948f6fb2321d9b13e2d2b08de3dcb8",
                "md5": "62898fe19f96929d7ae88c42b2046561",
                "sha256": "82134a42d0c9cb0f9eb8c8807141955e2413ea7e4f81e454a9dd2e53010617f6"
            },
            "downloads": -1,
            "filename": "typing_utilities-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "62898fe19f96929d7ae88c42b2046561",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 12665,
            "upload_time": "2025-07-11T08:53:52",
            "upload_time_iso_8601": "2025-07-11T08:53:52.906475Z",
            "url": "https://files.pythonhosted.org/packages/be/7f/6c33b2e385700fcd0540c3af4fe439948f6fb2321d9b13e2d2b08de3dcb8/typing_utilities-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "61b6b257e8ad8550f990dc5eb4709be7a269f664a80fb76a36444d1965ef4337",
                "md5": "8b4e6e9549bb8208f3ece0e895220caa",
                "sha256": "3a46dbd303bc9d5b78e7be8fc6ca9a0fe6cf5c606cd3d50ba3b055745295c0b4"
            },
            "downloads": -1,
            "filename": "typing_utilities-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "8b4e6e9549bb8208f3ece0e895220caa",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 15795,
            "upload_time": "2025-07-11T08:53:54",
            "upload_time_iso_8601": "2025-07-11T08:53:54.307322Z",
            "url": "https://files.pythonhosted.org/packages/61/b6/b257e8ad8550f990dc5eb4709be7a269f664a80fb76a36444d1965ef4337/typing_utilities-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-11 08:53:54",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "apmadsen",
    "github_project": "typing-utilities",
    "travis_ci": false,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "typing-utilities"
}
        
Elapsed time: 0.82004s