Skip to content

Commit bc0b551

Browse files
authored
Only use __getattr__ when node is not found (#5332)
1 parent 219fbf8 commit bc0b551

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

mypy/semanal.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3078,7 +3078,7 @@ def lookup_qualified(self, name: str, ctx: Context,
30783078
n = names.get(parts[i], None)
30793079
if n and isinstance(n.node, ImportedName):
30803080
n = self.dereference_module_cross_ref(n)
3081-
elif '__getattr__' in names:
3081+
elif not n and '__getattr__' in names:
30823082
gvar = self.create_getattr_var(names['__getattr__'],
30833083
parts[i], parts[i])
30843084
if gvar:

test-data/unit/check-modules.test

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2484,3 +2484,14 @@ from typing import Any
24842484
def __getattr__(attr: str) -> Any: ...
24852485
[builtins fixtures/module.pyi]
24862486
[out]
2487+
2488+
[case testNoGetattrInterference]
2489+
import testmod as t
2490+
def f(x: t.Cls) -> None:
2491+
reveal_type(x) # E: Revealed type is 'testmod.Cls'
2492+
[file testmod.pyi]
2493+
from typing import Any
2494+
def __getattr__(attr: str) -> Any: ...
2495+
class Cls: ...
2496+
[builtins fixtures/module.pyi]
2497+
[out]

0 commit comments

Comments
 (0)