typepy是在运行时用于变量类型检查器/验证器/转换器的python库。
typep的Python项目详细描述
typepy
Features
- 检查值类型
- 验证类型的值
- 将值从一种类型转换为另一种类型
python类型和typepy类之间的对应关系如下:
Python Type | typepy: Type Class |
---|---|
^{tt2}$ | Bool |
^{tt3}$ | DateTime |
^{tt4}$ | Dictionary |
^{tt5}$/^{tt6}$ (not infinity/NaN) | RealNumber |
^{tt5}$/^{tt6}$ (infinity) | Infinity |
^{tt5}$/^{tt6}$ (NaN) | Nan |
^{tt11}$ | Integer |
^{tt12}$ | List |
^{tt13}$ | None |
^{tt14}$ (not null) | String |
^{tt14}$ (null) | NullString |
^{tt14}$ (IP address) | IpAddress |
Usage
Type Check Method
Examples: | ^{pr 1}$ |
---|
Type Validation Method
Examples: | ^{pr 2}$ |
---|
For more information
类型检查/验证/转换结果根据 strict_levelvalue,它可以作为参数传递给typepy类构造函数。 更多信息可以在 API reference。
Installation
Install from PyPI
pip install typepy
如果使用typepy.DateTimeclass,请使用以下命令安装其他依赖项包
pip install typepy[datetime]
Install from PPA (for Ubuntu)
sudo add-apt-repository ppa:thombashi/ppa sudo apt update sudo apt install python3-typepy
Dependencies
python 2.7+或3.5+