有序集python库的带类型注释的存根
ordered-set-stubs的Python项目详细描述
ordered set stubs-用于ordered set python库的带有类型注释的stub
用法
例如,在ordered_set_stubs_test.py
文件中有以下代码:
fromordered_setimportOrderedSet# noinspection PyPep8Namingdefreceives_OrderedSet_int(ordered_set:'OrderedSet[int]')->'OrderedSet[int]':returnordered_setreceives_OrderedSet_int(OrderedSet(['ololo']))
运行mypy
检查代码并检查它是否返回错误:
$ mypy ordered_set_stubs_test.py
ordered_set_stubs_test.py:10: error: List item 0 has incompatible type "str"; expected "int"
在Python3.7中,您甚至可以删除引号:
from__future__importannotationsfromordered_setimportOrderedSet# noinspection PyPep8Namingdefreceives_OrderedSet_int(ordered_set:OrderedSet[int])->OrderedSet[int]:returnordered_setreceives_OrderedSet_int(OrderedSet(['ololo']))