Skip to content

Commit c901b71

Browse files
authored
Fix qualified_name for methods (#2453)
Fixes #2451.
2 parents 507d2ff + 83fe015 commit c901b71

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

mypy/semanal.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2640,7 +2640,11 @@ def lookup_fully_qualified_or_none(self, name: str) -> Optional[SymbolTableNode]
26402640
return n.names.get(parts[-1])
26412641

26422642
def qualified_name(self, n: str) -> str:
2643-
return self.cur_mod_id + '.' + n
2643+
if self.type is not None:
2644+
base = self.type._fullname
2645+
else:
2646+
base = self.cur_mod_id
2647+
return base + '.' + n
26442648

26452649
def enter(self) -> None:
26462650
self.locals.append(SymbolTable())

test-data/unit/check-incremental.test

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ a = produce()
376376
accept_int(a.foo())
377377

378378
[file mod2/__init__.py]
379-
from mod2.mod3 import CustomType
379+
from mod2.mod3 import CustomType
380380

381381
[file mod2/mod3/__init__.py]
382382
from mod2.mod3.mod4 import CustomType
@@ -407,13 +407,13 @@ tmp/mod1.py:6: error: Argument 1 to "accept_int" has incompatible type "str"; ex
407407
import mod1, mod2.mod3.mod5
408408

409409
[file mod1.py]
410-
from mod2 import produce
410+
from mod2 import produce
411411
def accept_int(x: int) -> None: pass
412412
a = produce()
413413
accept_int(a.foo())
414414

415415
[file mod2/__init__.py]
416-
from mod2.mod3 import produce
416+
from mod2.mod3 import produce
417417

418418
[file mod2/mod3/__init__.py]
419419
from mod2.mod3.mod4 import CustomType
@@ -548,7 +548,7 @@ def func2() -> str:
548548
[out2]
549549

550550
[case testIncrementalWithComplexDictExpression]
551-
import mod1
551+
import mod1
552552

553553
[file mod1.py]
554554
import mod1_private
@@ -570,7 +570,7 @@ my_dict = {
570570
[builtins fixtures/dict.pyi]
571571

572572
[case testIncrementalWithComplexConstantExpressionNoAnnotation]
573-
import mod1
573+
import mod1
574574

575575
[file mod1.py]
576576
import mod1_private
@@ -1178,7 +1178,7 @@ def foo(a: str) -> None: pass
11781178

11791179
[file client.py]
11801180
import good
1181-
import bad
1181+
import bad
11821182
from good import foo
11831183
foo(3)
11841184

@@ -1537,12 +1537,12 @@ tmp/foo.py:3: error: Argument 1 to "accept_int" has incompatible type "str"; exp
15371537
import foo
15381538

15391539
[file foo.py]
1540-
from mid import Outer
1540+
from mid import Outer
15411541
def accept_int(x: int) -> None: pass
15421542
accept_int(Outer.MyTuple(1, "b", "c").a)
15431543

15441544
[file mid.py]
1545-
from bar import Outer
1545+
from bar import Outer
15461546

15471547
[file bar.py]
15481548
from typing import NamedTuple
@@ -1634,3 +1634,20 @@ a = None # type: R
16341634
from . import m
16351635
R = m.R
16361636
a = None # type: R
1637+
1638+
[case testIncrementalBaseClassAttributeConflict]
1639+
class A: pass
1640+
class B: pass
1641+
1642+
class X:
1643+
attr = None # type: A
1644+
class Y:
1645+
attr = None # type: B
1646+
class Z(X, Y): pass
1647+
[stale]
1648+
[out]
1649+
main: note: In class "Z":
1650+
main:8: error: Definition of "attr" in base class "X" is incompatible with definition in base class "Y"
1651+
[out2]
1652+
main: note: In class "Z":
1653+
main:8: error: Definition of "attr" in base class "X" is incompatible with definition in base class "Y"

0 commit comments

Comments
 (0)