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

Đang mở
#21,889 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
65/100
Loại issue
Lỗi
Độ rõ ràng
Đặc tả rõ ràng
Mức độ hoạt động
Sôi nổi
Công nghệ
python
Lĩnh vực
devtools

Hướng nghiên cứu

Chạy bản tái hiện tối thiểu với các gói và cài đặt mypy_path đã nêu, sau đó lần theo lỗi qua errors.py tại add_error_info/_add_error_info, sử dụng messages.py và checkexpr.py làm đường dẫn lời gọi được báo cáo. So sánh điều này với chẩn đoán mô-đun trùng lặp hiện có và thêm độ bao phủ hồi quy. Được coi là hoàn tất khi lỗi arg-type thông thường được báo cáo một lần hoặc ánh xạ trùng lặp nhận được chẩn đoán hữu ích mà không xảy ra sự cố nội bộ.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

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.

Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Merge trung bình
1 ngày 9 giờ
Pull request đã merge (30 ngày)
56

Hướng dẫn đóng góp

Mở hướng dẫn đóng góp

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của python/mypy

Tất cả issue của python/mypy

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.