Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/video/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python MyPy不';t引发不同文件之间的类型不匹配_Python_Python 3.x_Python 3.8_Mypy - Fatal编程技术网

Python MyPy不';t引发不同文件之间的类型不匹配

Python MyPy不';t引发不同文件之间的类型不匹配,python,python-3.x,python-3.8,mypy,Python,Python 3.x,Python 3.8,Mypy,在具有以下结构的目录中: src/ my_module/ foo.py bar.py 我使用mypysrc/mymodule运行MyPy 如果单个文件中存在以下内容(例如foo.py): #foo.py def-hey(无论如何:str)->int: 返回234 嘿(22) 然后MyPy会抱怨,这是它应该抱怨的 $mypy src/myu模块 src/my_module/foo.py:4:错误:“hey”的参数1具有不兼容的类型“int”;预期的“str” 但是,如果一

在具有以下结构的目录中:

src/
  my_module/
    foo.py
    bar.py
我使用
mypysrc/mymodule
运行MyPy

如果单个文件中存在以下内容(例如
foo.py
):

#foo.py
def-hey(无论如何:str)->int:
返回234
嘿(22)
然后MyPy会抱怨,这是它应该抱怨的

$mypy src/myu模块
src/my_module/foo.py:4:错误:“hey”的参数1具有不兼容的类型“int”;预期的“str”
但是,如果一个文件从另一个文件调用函数:

#foo.py
def-hey(无论如何:str)->int:
返回234
#巴比
来自foo import嘿
嘿(22)
然后MyPy没有发现错误:

$mypy src/mymodule
成功:在2个源文件中未发现任何问题

如何确保MyPy检查不同文件之间的类型一致性?

使用MyPy 0.770,我得到:
my_模块/bar.py:3:错误:参数1到“hey”的类型不兼容“int”;应为“str”
您是否有
\uuuuu init\uuuuuuu.py
文件
mypy
可能将
foo
/
hey
解析为
Any
否则。