You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
# from __future__ import annotations # with or without makes no differencedeftest_a() ->None:
classSomeClass: # line 5defsome_method(self) ->None:
_=some_var# line 7some_var=None# not necessary for repro; stops error on line 7deftest_b() ->None:
instance: SomeClassclassSomeClass: # line 15passinstance=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 389a172 (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(-)
finite-state-machine
changed the title
mypy sometimes confuses nested class-in-functions of the same name
mypy sometimes confuses nested classes-in-functions which share the same name
Mar 19, 2024
(I'm going to mention @JukkaL, in no way as a criticism of their good work, but simply because they're most likely to be familiar with the code in question.)
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:
[mypy-play.net]
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 389a172 (which made its way into mypy 0.900):
Probably relates to #7281, #10431.
Your Environment
mypy.ini
(and other config files): none necessaryThe text was updated successfully, but these errors were encountered: