小编Tom*_*tse的帖子

mypy 找不到模块的实现或库存根

我有:

\n
foo/\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n\xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 bar.py\n\xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 baz\n    \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80 __init__.py\n    \xe2\x94\x94\xe2\x94\x80\xe2\x94\x80 alice.py\n
Run Code Online (Sandbox Code Playgroud)\n

在 中bar.py,我导入 Alice,它是一个空类,除了name属性设置为之外什么都没有"Alice"

\n
from baz.alice import Alice\n\na = Alice()\nprint(a.name)\n
Run Code Online (Sandbox Code Playgroud)\n

这可以正常运行:

\n
$ python foo/bar.py\nAlice\n
Run Code Online (Sandbox Code Playgroud)\n

但 mypy 抱怨道:

\n
$ mypy --version\nmypy 0.910\n$ mypy --strict .\nfoo/bar.py:1: error: Cannot find implementation or library stub for module named "baz.alice"\nfoo/bar.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports\nFound 1 error in 1 file (checked 6 source files)\n
Run Code Online (Sandbox Code Playgroud)\n

为什么 mypy 会抱怨?

\n

python mypy

43
推荐指数
1
解决办法
4万
查看次数

标签 统计

mypy ×1

python ×1