Skip to content

Commit 4a5e311

Browse files
authored
Fix crash related to module-level __getattr__ in incremental mode (#10430)
The `from_module_getattr` attribute of `Var` was not serialized, so subsequent runs didn't know about this being from `__getattr__` and tried to create a cross-ref to the definition which doesn't actually exist, resulting in a crash. Fixes #10429.
1 parent 204c7da commit 4a5e311

File tree

2 files changed

+29
-1
lines changed

2 files changed

+29
-1
lines changed

mypy/nodes.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -797,7 +797,7 @@ def deserialize(cls, data: JsonDict) -> 'Decorator':
797797
'is_self', 'is_initialized_in_class', 'is_staticmethod',
798798
'is_classmethod', 'is_property', 'is_settable_property', 'is_suppressed_import',
799799
'is_classvar', 'is_abstract_var', 'is_final', 'final_unset_in_class', 'final_set_in_init',
800-
'explicit_self_type', 'is_ready',
800+
'explicit_self_type', 'is_ready', 'from_module_getattr',
801801
] # type: Final
802802

803803

test-data/unit/check-incremental.test

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4239,6 +4239,34 @@ tmp/c.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#mi
42394239
tmp/c.py:1: error: Cannot find implementation or library stub for module named "a.b.c"
42404240
tmp/c.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports
42414241

4242+
[case testModuleGetattrIncrementalSerializeVarFlag]
4243+
import main
4244+
4245+
[file main.py]
4246+
from b import A, f
4247+
f()
4248+
4249+
[file main.py.3]
4250+
from b import A, f # foo
4251+
f()
4252+
4253+
[file b.py]
4254+
from c import A
4255+
def f() -> A: ...
4256+
4257+
[file b.py.2]
4258+
from c import A # foo
4259+
def f() -> A: ...
4260+
4261+
[file c.py]
4262+
from d import A
4263+
4264+
[file d.pyi]
4265+
def __getattr__(n): ...
4266+
[out1]
4267+
[out2]
4268+
[out3]
4269+
42424270
[case testAddedMissingStubs]
42434271
# flags: --ignore-missing-imports
42444272
from missing import f

0 commit comments

Comments
 (0)