Run without module detection logic
还没有人认领这个 Issue。
评估
调研方向
从 issue 中描述的 mypy 文件到模块的映射行为开始,并使用所示命令重现重复模块示例。定义该选项对于独立文件、已导入文件和多个包根目录的行为;当提议的 flag 能够避免不需要的重复模块错误,同时不破坏必要的 import 解析时,即视为完成。
由索引模型根据 Issue 内容生成。
描述
Feature
Allow mypy --no-module-detection (or similar flag) to run without mypy attempting to map files as modules. For example, linting standalone scripts should not require module detection magic.
Pitch
Mypy has (somewhat confusing?) file-to-module mapping logic explained in https://mypy.readthedocs.io/en/latest/running_mypy.html#mapping-file-paths-to-modules. The key take away is that mypy attempts to determine a module name for each imported file (in various ways). For example, a/b/c.py -> a.b.c.
However, the documentation doesn't give rationale for why this actually needs to be always done. If you merely want to check standalone files like mypy one.py then why does this require determining module name for the file?
(AFAIK, other linters like pylint don't have this kind of magic, perhaps because they don't follow imports like mypy does.)
If we have two files mypy one.py two.py and two imports one, then the detection logic is needed, so that module one is found (and it's fine).
However, if I have sub-directories with similarly named files, doing mypy one/file.py two/file.py throws:
two/file.py: error: Duplicate module named 'file' (also at 'one/file.py')
But these are two standalone files, in separate directories, not part of the same package. Why is the error there?
Similar trouble is faced when maintaining a monorepo with multiple packages:
package1/
setup.py
...
package2/
setup.py
...
Mypy will throw error about duplicate module name on setup.py files (and others).
Now, without arguing on how mypy should determine module name of the files is looks up (surely there's reasoning for that), I'm suggesting to add an option to completely skip this magic. In my case, I always pip install -e . the packages that I'm developing, so whatever imports the code (wherever), those imports are already resolvable. All the packages are already importable and whatever files reside out of the packages, are stand-alone scripts and never imported.
One downside is that something like this would no longer work:
package1/
src/
...
setup.py
tasks.py # imports util.py
util.py
For that I don't have suggestion :( Could it be solved by multiple entries in MYPYPATH or PYTHONPATH?
- 主要语言
- Python
- 星标
- 20.6k
- 派生
- 3.3k
- 平均合并
- 1 天 18 小时
- 30 天内合并 PR
- 54
贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
python/mypy 的其他 Issue
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
-
bug
难度 2/5 1-3 小时 新手友好度 78/100
-
bug
难度 2/5 1-3 小时 新手友好度 76/100
-
documentation
难度 2/5 1-3 小时 新手友好度 72/100
-
bug topic-configuration topic-error-reporting
难度 2/5 1-3 小时 新手友好度 68/100
相似的 Issue
-
link-check link-check:sphinx-theme
难度 2/5 1-3 小时 新手友好度 72/100
-
难度 2/5 1-3 小时 新手友好度 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
难度 2/5 1-3 小时 新手友好度 88/100
OpenHands/extensions#626 · 1 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 90/100
CSCfi/sd-search-api#39 ·
-
难度 1/5 1 小时以内 新手友好度 90/100