为什么 mypy 检查我排除的文件?

问题描述

我正在尝试为项目设置 mypy 类型检查。我想排除一堆文件/目录来启动,这样我们至少可以强制执行新代码的类型检查,然后我们可以随着时间的推移销毁排除列表。不幸的是,mypy 忽略了我的排除配置,我不知道为什么。

我创建了一个包含以下内容mypy.ini 配置文件

[mypy]
python_version = 3.8
exclude = /examples/

但是当我运行 mypy --verbose . 时,它仍然会发现该目录中的文件并出现错误。日志消息告诉我它正在查看我的排除配置,但显然忽略了它:

LOG:  Mypy Version:           0.812
LOG:  Config File:            mypy.ini
LOG:  Configured Executable:  /Library/Developer/CommandLinetools/usr/bin/python
3
LOG:  Current Executable:     /Library/Developer/CommandLinetools/usr/bin/python
3
LOG:  Cache Dir:              .mypy_cache
LOG:  Compiled:               True
LOG:  Exclude:                /examples/
<snipped>
LOG:  Found source:           BuildSource(path='./examples/fib.py',module='fib',has_text=False,base_dir='/Users/user/a/examples')
LOG:  Found source:           BuildSource(path='./examples/fib_iter.py',module='fib_iter',base_dir='/Users/user/a/examples')
<snipped>
examples/fib.py: error: Duplicate module named 'fib' (also at './examples/a/fib.py')
examples/fib.py: note: Are you missing an __init__.py? Alternatively,consider using --exclude to avoid checking one of them.
Found 1 error in 1 file (errors prevented further checking)

为什么我的排除配置不起作用?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)