8000 New semantic analyzer: fix deserialization crash with module __getatt… · python/mypy@65757aa · GitHub
[go: up one dir, main page]

Skip to content

Navigation Menu

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 65757aa

Browse files
JukkaLilevkivskyi
authored andcommitted
New semantic analyzer: fix deserialization crash with module __getattr__ (#6614)
We could generate a cross ref to a dummy node from module-level `__getattr__` which would cause a crash.
1 parent d2cf9c6 commit 65757aa

File tree

3 files changed

+18
-2
lines changed
< 8000 div>

3 files changed

+18
-2
lines changed

mypy/lookup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def lookup_fully_qualified(name: str, modules: Dict[str, MypyFile],
4444
key = rest.pop()
4545
if key not in names:
4646
if raise_on_missing:
47-
assert key in names, "Cannot find %s for %s" % (key, name)
47+
assert key in names, "Cannot find component %r for %r" % (key, name)
4848
return None
4949
stnode = names[key]
5050
if not rest:

mypy/nodes.py

+3Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2938,7 +2938,9 @@ def serialize(self, prefix: str, name: str) -> JsonDict:
29382938
if prefix is not None:
29392939
fullname = self.node.fullname()
29402940
if (fullname is not None and '.' in fullname and
2941-
fullname != prefix + '.' + name):
2941+
fullname != prefix + '.' + name
2942+
and not (isinstance(self.node, Var)
2943+
and self.node.from_module_getattr)):
29422944
data['cross_ref'] = fullname
29432945
return data
29442946
data['node'] = self.node.serialize()

test-data/unit/check-newsemanal.test

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2035,3 +2035,17 @@ import pack.mod
20352035
import a
20362036
[out]
20372037
[out2]
2038+
2039+
[case testNewAnalyzerModuleGetattrSerialize_incremental]
2040+
import a
2041+
[file a.py]
2042+
import p
2043+
[file a.py.2]
2044+
import p
2045+
reveal_type(p.y)
2046+
[file p.pyi]
2047+
from pp import x as y
2048+
[file pp.pyi]
2049+
def __getattr__(attr): ...
2050+
[out2]
2051+
tmp/a.py:2: error: Revealed type is 'Any'

0 commit comments

Comments
 (0)
0