Python 2.x 的类型提示
项目描述
# Takayi
Python 2.X 的类型提示。
`takayi` 在日语中意味着 `高`。
## 使用方法
```python
from takayi.parser import Parser, typehints
parser = Parser()
# ==================================================
@typehints(parser)
def get_sum(x, y)
# type: (int, int) -> int
return x + y
_sum = get_sum(1, 2) # 结果应该是 3
# takayi.exc.ParameterTypeError: Expect => [<type 'int'>, <type 'int'>], Actually => [<type 'int'>, <type 'str'>]
_err_sum = get_sum(1, 'hello')
# ==================================================
@typehints(parser)
def test(x, y=1)
# type: (int, y: int) -> int
return x + y
assert test(1, y=10) == 11
# ==================================================
class Node(object): pass
node = Node()
@typehints(parser, attach_cls=Node)
def get_node()
# type: () -> Node
return node
```
## TODO
- [x] 支持kwargs类型检查
- [ ] 更多类型。FYI: [pep484](https://pythonlang.cn/dev/peps/pep-0484/)
Python 2.X 的类型提示。
`takayi` 在日语中意味着 `高`。
## 使用方法
```python
from takayi.parser import Parser, typehints
parser = Parser()
# ==================================================
@typehints(parser)
def get_sum(x, y)
# type: (int, int) -> int
return x + y
_sum = get_sum(1, 2) # 结果应该是 3
# takayi.exc.ParameterTypeError: Expect => [<type 'int'>, <type 'int'>], Actually => [<type 'int'>, <type 'str'>]
_err_sum = get_sum(1, 'hello')
# ==================================================
@typehints(parser)
def test(x, y=1)
# type: (int, y: int) -> int
return x + y
assert test(1, y=10) == 11
# ==================================================
class Node(object): pass
node = Node()
@typehints(parser, attach_cls=Node)
def get_node()
# type: () -> Node
return node
```
## TODO
- [x] 支持kwargs类型检查
- [ ] 更多类型。FYI: [pep484](https://pythonlang.cn/dev/peps/pep-0484/)
项目详情
下载文件
下载适合您平台的文件。如果您不确定选择哪个,请了解更多关于 安装包 的信息。
源分布
takayi-0.3.3.tar.gz (4.7 kB 查看散列)
构建分布
takayi-0.3.3-py2-none-any.whl (7.5 kB 查看散列)