typepyPython 变量类型检查器
typepy 是一个 Python 库,用于运行时的变量类型检查器/验证器/转换器。
特征
- 检查值的类型
- 验证类型的值
- 将值从一种类型转换为另一种类型
Python 类型和typepy类的对应关系如下:
支持的类型
| Python 类型 | typepy:类型类 |
|---|---|
bool | Bool |
datetime | DateTime |
dict | Dictionary |
float/decimal.Decimal (not infinity/NaN) | RealNumber |
float/decimal.Decimal (infinity) | Infinity |
float/decimal.Decimal (NaN) | Nan |
int | Integer |
list | List |
None | None |
str (not null) | String |
str (null) | NullString |
str (IP address) | IpAddress |
安装
安装:pip
pip install typepy
如果使用typepy.DateTime类,请使用以下命令安装其他依赖包
pip install typepy[datetime]
安装:conda
conda install -c conda-forge typepy
安装: apt
sudo add-apt-repository ppa:thombashi/ppa
sudo apt update
sudo apt install python3-typepy
依赖关系
- Python 3.6+
- Python 包依赖(自动安装)
可选依赖
这些软件包可以通过pip install typepy[datetime]以下方式安装:
- python-dateutil
- pytz
评论
