mypy sometimes emits fewer errors when running on multiple files at once

未关闭
#14,348 0 条评论 1 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
4/5
预计耗时
3-5 天
新手友好度
35/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
python
领域
compilers

调研方向

解压 repro.zip,并使用 foo.py 和 bar.py 运行报告中的两个命令,以复现不同的诊断结果。跟踪文件一起检查时如何处理 mymodule.a 和 mymodule.b 的导入,然后确保在两次调用中仍然报告缺少属性的错误。

由索引模型根据 Issue 内容生成。

描述

bug

Bug Report

Hello there,

I am witnessing (rare) cases where mypy emits fewer errors when running on multiple files at the same time than when running on each file individually.

More specifically, I noticed that mypy can fail to report an error when an import for a submodule is missing a one file but present in another file.

I failed to find anything relevant in the documentation or in the existing issues, so I thought I'd let you know. Below is my attempt at a minimal reproducible example.

To Reproduce

(Since multiple files are needed, here is an archive with the reproduction case: repro.zip)

Given a module mymodule with nested modules a and b, and this file foo.py:

import mymodule.a


def blah() -> None:
    mymodule.b.fn()


blah()

As expected, when called on foo.py, mypy emits an error:

$ mypy --cache-dir /dev/null foo.py
foo.py:5: error: Module has no attribute "b"
Found 1 error in 1 file (checked 1 source file)

yet if I add to mypy's command line a second file which does import mymodule.b, say bar.py:

import mymodule.b

then mypy does not emit the error any more, even though I would expect it to:

$ mypy --cache-dir /dev/null foo.py bar.py
Success: no issues found in 2 source files

Your Environment

I used mypy 0.991 on Ubuntu 22.04 with python 3.10.6; I can reproduce this behavior with master, as well as python 3.8, and older versions of mypy.

主要语言
Python
星标
20.6k
派生
3.3k
平均合并
1 天 18 小时
30 天内合并 PR
54

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

python/mypy 的其他 Issue

查看 python/mypy 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。