mypy sometimes confuses nested classes-in-functions which share the same name
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
- 35/100
Hướng nghiên cứu
Tái hiện ví dụ tối thiểu với mypy 1.9.0 và so sánh với 0.800, sau đó kiểm tra commit bisection và các tệp phân tích ngữ nghĩa mà commit đó đã thay đổi, đặc biệt là mypy/semanal.py. Bắt đầu với test-data/unit/check-incremental.test là vị trí kiểm thử được đề cập; hoàn thành khi hai định nghĩa SomeClass có phạm vi riêng biệt không còn tạo ra lỗi incompatible-assignment.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
Bug Report
In some circumstances, mypy will confuse two classes of the same name, even if they're declared in non-overlapping scopes.
To Reproduce
Check the following ~minimal example with mypy:
# from __future__ import annotations # with or without makes no difference
def test_a() -> None:
class SomeClass: # line 5
def some_method(self) -> None:
_ = some_var # line 7
some_var = None # not necessary for repro; stops error on line 7
def test_b() -> None:
instance: SomeClass
class SomeClass: # line 15
pass
instance = SomeClass()
# error: Incompatible types in assignment (expression
# has type "SomeClass@15", variable has type
# "SomeClass@5") [assignment]
Expected Behavior
No errors.
Actual Behavior
The tool confuses the two classes of the same name (SomeClass), despite these being declared in entirely different scopes.
Bisection
The problem appears to have been introduced by https://github.com/python/mypy/commit/389a1725c1df7fad4e2605360157c9f910cb502c (which made its way into mypy 0.900):
389a1725c1df7fad4e2605360157c9f910cb502c is the first bad commit
commit 389a1725c1df7fad4e2605360157c9f910cb502c
Author: Jukka Lehtosalo <jukka.lehtosalo@iki.fi>
Date: Thu May 6 14:32:36 2021 +0100
Fix crash with nested NamedTuple in incremental mode (#10431)
The name of the nested tuple type was inconsistent. Sometimes if was stored
using the full name in the module symbol table.
Also improve the internal API for creating classes to be less error-prone.
Work on #7281.
mypy/semanal.py | 10 +++++++---
mypy/semanal_enum.py | 9 +++++----
mypy/semanal_namedtuple.py | 2 +-
mypy/semanal_newtype.py | 11 ++++++-----
mypy/semanal_shared.py | 2 +-
mypy/semanal_typeddict.py | 14 ++++++++------
test-data/unit/check-incremental.test | 26 ++++++++++++++++++++++++++
7 files changed, 54 insertions(+), 20 deletions(-)
Probably relates to #7281, #10431.
Your Environment
- Mypy version used: 1.9.0, 0.900, but not 0.800 (see: "bisection")
- Mypy command-line flags: none necessary
- Mypy configuration options from
mypy.ini(and other config files): none necessary - Python version used: 3.8, 3.12
- Ngôn ngữ chính
- Python
- Star
- 20.6k
- Fork
- 3.3k
- Merge trung bình
- 1 ngày 18 giờ
- Pull request đã merge (30 ngày)
- 54
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- 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.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của python/mypy
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 78/100
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
documentation
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
-
bug topic-configuration topic-error-reporting
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 65/100
qgis/QGIS-Documentation#11275 ·
-
bug priority:normal ready-for-dev
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 88/100
OpenHands/extensions#626 · 1 bình luận ·
-
Change observation tooltip text Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
CSCfi/sd-search-api#39 ·
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 90/100
-
please add to porn list Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
StevenBlack/hosts#3255 ·