python typing tool
Project description
功能
安装
pip install typing_tool
Or
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: 设置类型检查的最大深度
- max_sample: 设置最大采样数
- protocol_type_strict: 是否严格检查 Protocol 类型
- dataclass_type_strict: 是否严格检查 dataclass 类型
自动重载
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
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
typing_tool-0.1.4.tar.gz
(10.7 kB
view details)
Built Distribution
File details
Details for the file typing_tool-0.1.4.tar.gz
.
File metadata
- Download URL: typing_tool-0.1.4.tar.gz
- Upload date:
- Size: 10.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 3ac49c1b73732acbb38aa59f76407f8d2cc4d5d8c974c94bae1de437530c81ae |
|
MD5 | 90ce85e1d7a8074b93aeba54de9e0b6a |
|
BLAKE2b-256 | 13e244fd2dbe7bff7ec3f1fdb9db68c5a2db31c655fd35a6369446a52214bed8 |
File details
Details for the file typing_tool-0.1.4-py3-none-any.whl
.
File metadata
- Download URL: typing_tool-0.1.4-py3-none-any.whl
- Upload date:
- Size: 10.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: pdm/2.20.0.post1 CPython/3.10.12 Linux/6.5.0-1025-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51d7bda1dcaf3dcbc4ab72b3046300418be56ea4985962302ead2dee7ecde9bc |
|
MD5 | 0f93349443b7234baa36e1c9d57697d2 |
|
BLAKE2b-256 | 7955d54532d6f23de0095235bfbde8cc9995994732294b9e7d8c3f2854ba5cbe |