mypy没有检测到基本类型错误

时间:2016-01-13 02:36:40

标签: python static-typing mypy

使用python 3.5.1。和当前使用git安装mypy, mypy标志错误1& 2,但它没有报告3

我做错了什么,或者这是一个错误,还是这个已知问题?

import typing

def test_ordered_dict(od: typing.Dict[str,int]) -> typing.Dict[str,int]:
    return 1   #type error 1

a = test_ordered_dict(1)   #type error 2

def test_me():
    a = test_ordered_dict(1)  # type error 3 is not reported

1 个答案:

答案 0 :(得分:3)

我对文档的理解:http://mypy.readthedocs.org/en/latest/basics.html是mypy只会检查一个东西(模块,函数,等等),如果它指示它应该检查它(通过在模块级别导入类型或通过注释a功能)。

所以检查1是因为它在一个键入的函数中,2被检查,因为导入类型表明你的模块是键入的,它在模块范围但是3在无类型函数的范围内,所以它被忽略。