python / python/mypy

`type: ignore` comments on imports of external package lead to `[unused-ignore]` error codes every other run

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

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

bug topic-configuration topic-incremental
Ngôn ngữ chính
Python
Star
20.6k
Fork
3.3k
Chỉ số merge pull request
Chỉ số pull request đang chờ

Mô tả

Bug Report

When running mypy with --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports, putting a type: ignore[attr-defined] on an import will have mypy report an Unused "type: ignore" comment [unused-ignore] every other run, unless the cache is being cleared between runs.

To Reproduce

from opentelemetry.instrumentation.asgi import (  # type: ignore[attr-defined]
    OpenTelemetryMiddleware,
)

(Since this only seems to work with external packages, some setup is required)

  1. Run pip install opentelemetry-instrumentation-asgi opentelemetry-distro
  2. Add the code snippet below to file.py
  3. Run mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no error
  4. Run mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observe an [unused-ignore] error
  5. Run mypy --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports file.py: Observer no error
  6. Repeat the cycle as many times as you like :)

When removing the cache between runs, all works well, so I suspect it has something to do with caching.

Your Environment

  • Mypy version used: 1.18.2, main
  • Mypy command-line flags: --warn-unused-ignore --no-namespace-packages --warn-unused-ignores --ignore-missing-imports
  • Mypy configuration options from mypy.ini (and other config files): -
  • Python version used: 3.13.7

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.

Hướng nghiên cứu

Tái hiện kết quả luân phiên với file.py bằng lệnh mypy được liệt kê và import opentelemetry, sau đó truy vết cách xử lý liên quan đến cache đối với trạng thái unused-ignore. Thêm một bài kiểm thử hồi quy cho các lần chạy lặp lại từ cache; hoàn tất khi lệnh nhất quán không báo lỗi [unused-ignore] không có cơ sở.

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

Đánh giá

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

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.