类型的功能
typish的Python项目详细描述
键入
- 用于彻底检查类型的功能
- 考虑泛型的实例检查
- typesafe duck键入
安装
pip install typish
内容
功能
Function | Description |
---|---|
^{ | Returns whether ^{ |
^{ | Returns whether ^{ |
^{ | Return the "origin" of a generic type. E.g. ^{ |
^{ | Return the arguments of a generic type. E.g. ^{ |
^{ | Return the ^{ |
^{ | Return the (generic) type of an instance. E.g. a list of ints will give ^{ |
^{ | Return the closest common ancestor of the given instances. |
^{ | Return the closest common ancestor of the given classes. |
类型
Type | Description |
---|---|
^{ | A generic Type var. |
^{ | A Type var for keys in a dict. |
^{ | A type var for values in a dict. |
^{ | The type of emptiness (= ^{ |
^{ | The type of something unknown. |
^{ | The type of a module. |
^{ | The type of ^{ |
接口
用typish.Interface
定义接口。
示例:
Duck=Interface['walk':Callable[[],None],'quack':Callable[[],None]]
任何在接口中定义了正确类型的属性都是 视为该接口的实例(类、对象、甚至模块…)。
您可以使用内置的isinstance
或typish.instance_of
检查接口。