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_tool import auto_overload
@overload
def process(response: None) -> None:
return None
@overload
def process(responsel: int, response2: str) -> tuple[int, str]:
return response1, response2
@overload
def process(response: bytes) -> str:
return response.decode()
@auto_convert
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.3.tar.gz
(10.7 kB
view details)
Built Distribution
File details
Details for the file typing_tool-0.1.3.tar.gz
.
File metadata
- Download URL: typing_tool-0.1.3.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 | fa0f6d234f99ad153ae8e1e4dce856d1fb71cf00e692583e8ac86518fa7a938f |
|
MD5 | b74e0b3cc32b13bb701a6aece1c10fe1 |
|
BLAKE2b-256 | 10f6824b89d9034a832bc6361608a831810ffad49e4e15fb011f9e3d664409a0 |
File details
Details for the file typing_tool-0.1.3-py3-none-any.whl
.
File metadata
- Download URL: typing_tool-0.1.3-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 | ff2f21c791d4738774b2fc6e738effa9f2534df220700f4b120663e46c896471 |
|
MD5 | 340015ff3c911a02a0e63bd9ebd634eb |
|
BLAKE2b-256 | 71bd87e5dc72c3f512119c4376099e6833936784b34be5c06c168b984c3c387a |