Crash when packages and mypy_path discover one file under two module names

未关闭
#21,889 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

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

调研方向

使用所述的软件包和 mypy_path 设置运行最小复现,然后通过 errors.py 中的 add_error_info/_add_error_info 跟踪失败,并将 messages.py 和 checkexpr.py 作为报告的调用路径。将其与现有的重复模块诊断进行比较,并添加回归覆盖。完成的标准是:普通的 arg-type 错误只报告一次,或者重复映射能得到有用的诊断而不会发生内部崩溃。

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

描述

crash

Mypy crashes while reporting an ordinary type error when one physical package is discovered under two configured package roots. The existing duplicate-module diagnostic does not catch this packages + mypy_path configuration.

Minimal reproduction

Directory layout:

pyproject.toml
src/
  outer/
    __init__.py
    inner/
      example/
        __init__.py
        module.py

pyproject.toml:

[tool.mypy]
python_version = "3.14"
strict = true
mypy_path = ["src", "src/outer/inner"]
packages = ["outer", "example"]
explicit_package_bases = true

src/outer/inner/example/module.py:

def takes_int(value: int) -> None:
    pass


def broken() -> None:
    takes_int("not an int")

The __init__.py files are empty.

$ uv run --no-project --with mypy==2.3.1 mypy --no-incremental --show-traceback
src/outer/inner/example/module.py:6: error: Argument 1 to "takes_int" has incompatible type "str"; expected "int"  [arg-type]
.../src/outer/inner/example/module.py:6: error: INTERNAL ERROR -- Please try using mypy master on GitHub:
https://mypy.readthedocs.io/en/stable/common_issues.html#using-a-development-mypy-build
Please report a bug at https://github.com/python/mypy/issues
version: 2.3.1
.../src/outer/inner/example/module.py:6: note: use --pdb to drop into pdb
Traceback (most recent call last):
  File "mypy/checkexpr.py", line 6163, in accept
  File "mypy/checkexpr.py", line 499, in visit_call_expr
  File "mypy/checkexpr.py", line 630, in visit_call_expr_inner
  File "mypy/checkexpr.py", line 1498, in check_call_expr_with_callee_type
  File "mypy/checkexpr.py", line 1591, in check_call
  File "mypy/checkexpr.py", line 1873, in check_callable_call
  File "mypy/checkexpr.py", line 2762, in check_argument_types
  File "mypy/checkexpr.py", line 2799, in check_arg
  File "mypy/messages.py", line 812, in incompatible_argument
  File "mypy/messages.py", line 282, in fail
  File "mypy/messages.py", line 260, in report
  File "mypy/errors.py", line 680, in report
  File "mypy/errors.py", line 810, in add_error_info
  File "mypy/errors.py", line 684, in _add_error_info
    assert file not in self.flushed_files
AssertionError

Expected: report the ordinary arg-type error once, or reject the duplicate physical-file/module-name mapping with a useful diagnostic. Mypy should not crash.

This also reproduces on current master d32c4d38770745dd9fb6a0279204425e6070e6ad (2.4.0+dev.d32c4d).

Environment

  • macOS arm64
  • Python 3.14.7
  • mypy 2.3.1 compiled wheel

Prior issue search

This seems to be a similar underlying duplicate-file condition as #4881 and #7510, but both are closed because mypy added a "Source file found twice under different module names" diagnostic. That diagnostic does not prevent this configuration-driven variant in 2.3.1 or current master.

AI Disclosure

gpt-5.6-sol used to synthesize the minimal reproducer. I've reproduced this manually.

主要语言
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 摘要。