typing_tool


Nametyping_tool JSON
Version 0.1.6 PyPI version JSON
download
home_pageNone
Summarypython typing tool
upload_time2024-11-08 08:24:20
maintainerNone
docs_urlNone
authorNone
requires_python>=3.10
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            <div align="center">

# typing_tool

_**Typing_Tool** 是一个 Python 类型工具_


 [![CodeFactor](https://www.codefactor.io/repository/github/lacia-hIE/typing_tool/badge)](https://www.codefactor.io/repository/github/lacia-hIE/typing_tool)
 [![GitHub](https://img.shields.io/github/license/lacia-hIE/typing_tool)](https://github.com/lacia-hIE/typing_tool/blob/master/LICENSE)
 [![CodeQL](https://github.com/lacia-hIE/typing_tool/workflows/CodeQL/badge.svg)](https://github.com/lacia-hIE/typing_tool/blob/master/.github/workflows/codeql.yml)

</div>

## 功能



## 安装

```sh
pip install typing_tool
```

Or

```sh
pdm add typing_tool
```

## 入门指南

typing_tool 是一个用于增强 Python 类型检查能力的工具库。特别地,它扩展了 isinstance 和 issubclass 函数的能力,使其能够处理更复杂的类型检查需求。

## 支持类型

### like_isinstance

* 基础类型 str/int/...
* 容器泛型 list[T]/dict[K, V]/...
* Union 类型类型
* Type 
* TypeVar 类型变量
* 泛型类 Generic[T]
* Annotated/Field 注解类型
* Protocol 协议类型
* Protocol[T] 泛型协议类型
* TypedDict 字典类型
* dataclass 数据类
* dataclass[T] 泛型数据类

### like_issubclass

* 基础类型 str/int
* 容器泛型 list[T]/dict[K, V]
* Union 类型类型
* NewType 新类型
* Type 
* TypeVar 类型变量
* 泛型类 Generic[T]
* Protocol 协议类型
* Protocol[T] 泛型协议类型

### Check Config

* `depth`: 设置类型检查的最大深度,默认值为 `5`
* `max_sample`: 设置最大采样数,默认值为 `-1`
* `protocol_type_strict`: 是否严格检查 `Protocol` 类型,默认值为 `False`
* `dataclass_type_strict`: 是否严格检查 `dataclass` 类型,默认值为 `False`

### 自动重载

```python
from typing import Any
from typing_extensions import overload
from typing_tool import auto_overload

@overload
def process(response: None) -> None:
    return None
@overload
def process(response1: int, response2: str) -> tuple[int, str]:
    return response1, response2
@overload
def process(response: bytes) -> str:
    return response.decode()
@auto_overload()
def process(*args, **kwargs) -> Any: ...

assert process(None) is None
assert process(1, "2") == (1, "2")
assert process(b"test") == "test"
```

### 注意

* NewType 无法在运行时进行 like_isinstance

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "typing_tool",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.10",
    "maintainer_email": null,
    "keywords": null,
    "author": null,
    "author_email": "luxuncang <luxuncang@qq.com>",
    "download_url": "https://files.pythonhosted.org/packages/91/24/1a1242156363f51bc8677fc5a44160350bdcf8e658b13273962f1d5870c1/typing_tool-0.1.6.tar.gz",
    "platform": null,
    "description": "<div align=\"center\">\n\n# typing_tool\n\n_**Typing_Tool** \u662f\u4e00\u4e2a Python \u7c7b\u578b\u5de5\u5177_\n\n\n [![CodeFactor](https://www.codefactor.io/repository/github/lacia-hIE/typing_tool/badge)](https://www.codefactor.io/repository/github/lacia-hIE/typing_tool)\n [![GitHub](https://img.shields.io/github/license/lacia-hIE/typing_tool)](https://github.com/lacia-hIE/typing_tool/blob/master/LICENSE)\n [![CodeQL](https://github.com/lacia-hIE/typing_tool/workflows/CodeQL/badge.svg)](https://github.com/lacia-hIE/typing_tool/blob/master/.github/workflows/codeql.yml)\n\n</div>\n\n## \u529f\u80fd\n\n\n\n## \u5b89\u88c5\n\n```sh\npip install typing_tool\n```\n\nOr\n\n```sh\npdm add typing_tool\n```\n\n## \u5165\u95e8\u6307\u5357\n\ntyping_tool \u662f\u4e00\u4e2a\u7528\u4e8e\u589e\u5f3a Python \u7c7b\u578b\u68c0\u67e5\u80fd\u529b\u7684\u5de5\u5177\u5e93\u3002\u7279\u522b\u5730\uff0c\u5b83\u6269\u5c55\u4e86 isinstance \u548c issubclass \u51fd\u6570\u7684\u80fd\u529b\uff0c\u4f7f\u5176\u80fd\u591f\u5904\u7406\u66f4\u590d\u6742\u7684\u7c7b\u578b\u68c0\u67e5\u9700\u6c42\u3002\n\n## \u652f\u6301\u7c7b\u578b\n\n### like_isinstance\n\n* \u57fa\u7840\u7c7b\u578b str/int/...\n* \u5bb9\u5668\u6cdb\u578b list[T]/dict[K, V]/...\n* Union \u7c7b\u578b\u7c7b\u578b\n* Type \n* TypeVar \u7c7b\u578b\u53d8\u91cf\n* \u6cdb\u578b\u7c7b Generic[T]\n* Annotated/Field \u6ce8\u89e3\u7c7b\u578b\n* Protocol \u534f\u8bae\u7c7b\u578b\n* Protocol[T] \u6cdb\u578b\u534f\u8bae\u7c7b\u578b\n* TypedDict \u5b57\u5178\u7c7b\u578b\n* dataclass \u6570\u636e\u7c7b\n* dataclass[T] \u6cdb\u578b\u6570\u636e\u7c7b\n\n### like_issubclass\n\n* \u57fa\u7840\u7c7b\u578b str/int\n* \u5bb9\u5668\u6cdb\u578b list[T]/dict[K, V]\n* Union \u7c7b\u578b\u7c7b\u578b\n* NewType \u65b0\u7c7b\u578b\n* Type \n* TypeVar \u7c7b\u578b\u53d8\u91cf\n* \u6cdb\u578b\u7c7b Generic[T]\n* Protocol \u534f\u8bae\u7c7b\u578b\n* Protocol[T] \u6cdb\u578b\u534f\u8bae\u7c7b\u578b\n\n### Check Config\n\n* `depth`: \u8bbe\u7f6e\u7c7b\u578b\u68c0\u67e5\u7684\u6700\u5927\u6df1\u5ea6\uff0c\u9ed8\u8ba4\u503c\u4e3a `5`\n* `max_sample`: \u8bbe\u7f6e\u6700\u5927\u91c7\u6837\u6570\uff0c\u9ed8\u8ba4\u503c\u4e3a `-1`\n* `protocol_type_strict`: \u662f\u5426\u4e25\u683c\u68c0\u67e5 `Protocol` \u7c7b\u578b\uff0c\u9ed8\u8ba4\u503c\u4e3a `False`\n* `dataclass_type_strict`: \u662f\u5426\u4e25\u683c\u68c0\u67e5 `dataclass` \u7c7b\u578b\uff0c\u9ed8\u8ba4\u503c\u4e3a `False`\n\n### \u81ea\u52a8\u91cd\u8f7d\n\n```python\nfrom typing import Any\nfrom typing_extensions import overload\nfrom typing_tool import auto_overload\n\n@overload\ndef process(response: None) -> None:\n    return None\n@overload\ndef process(response1: int, response2: str) -> tuple[int, str]:\n    return response1, response2\n@overload\ndef process(response: bytes) -> str:\n    return response.decode()\n@auto_overload()\ndef process(*args, **kwargs) -> Any: ...\n\nassert process(None) is None\nassert process(1, \"2\") == (1, \"2\")\nassert process(b\"test\") == \"test\"\n```\n\n### \u6ce8\u610f\n\n* NewType \u65e0\u6cd5\u5728\u8fd0\u884c\u65f6\u8fdb\u884c like_isinstance\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "python typing tool",
    "version": "0.1.6",
    "project_urls": null,
    "split_keywords": [],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "5b1e4a05d2220e231095e096f9ce332583e5b7502ff388eae28adab8028f3ecd",
                "md5": "e1bad0fc14f231366ca7b2bc5e4e175f",
                "sha256": "67e5425f798352f3843b6ffbee66539233a6234b6e73a4796b8fd175f677f021"
            },
            "downloads": -1,
            "filename": "typing_tool-0.1.6-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "e1bad0fc14f231366ca7b2bc5e4e175f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.10",
            "size": 10493,
            "upload_time": "2024-11-08T08:24:19",
            "upload_time_iso_8601": "2024-11-08T08:24:19.409190Z",
            "url": "https://files.pythonhosted.org/packages/5b/1e/4a05d2220e231095e096f9ce332583e5b7502ff388eae28adab8028f3ecd/typing_tool-0.1.6-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "91241a1242156363f51bc8677fc5a44160350bdcf8e658b13273962f1d5870c1",
                "md5": "1db014b31ae41f2852577333db0863c4",
                "sha256": "dd092a4e74974669d1311c2b47c0d7af50b9b59dc418b68c2791d2b001f38934"
            },
            "downloads": -1,
            "filename": "typing_tool-0.1.6.tar.gz",
            "has_sig": false,
            "md5_digest": "1db014b31ae41f2852577333db0863c4",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.10",
            "size": 14500,
            "upload_time": "2024-11-08T08:24:20",
            "upload_time_iso_8601": "2024-11-08T08:24:20.966002Z",
            "url": "https://files.pythonhosted.org/packages/91/24/1a1242156363f51bc8677fc5a44160350bdcf8e658b13273962f1d5870c1/typing_tool-0.1.6.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-11-08 08:24:20",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "typing_tool"
}
        
Elapsed time: 1.02361s