Skip to content

Fix serialization of redefined nodes #7413

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Aug 29, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions mypy/fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ def visit_symbol_table(self, symtab: SymbolTable) -> None:
stnode = lookup_qualified_stnode(self.modules, cross_ref,
self.allow_missing)
if stnode is not None:
assert stnode.node is not None
value.node = stnode.node
elif not self.allow_missing:
assert stnode is not None, "Could not find cross-ref %s" % (cross_ref,)
Expand Down
6 changes: 4 additions & 2 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2986,8 +2986,10 @@ def serialize(self, prefix: str, name: str) -> JsonDict:
assert self.node is not None, '%s:%s' % (prefix, name)
if prefix is not None:
fullname = self.node.fullname()
if (fullname is not None and '.' in fullname and
fullname != prefix + '.' + name
if (fullname is not None and '.' in fullname
and fullname != prefix + '.' + name
# If it only doesn't match because of -redefinition, that is OK
and fullname != prefix + '.' + name.split('-redefinition')[0]
and not (isinstance(self.node, Var)
and self.node.from_module_getattr)):
data['cross_ref'] = fullname
Expand Down
1 change: 1 addition & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3114,6 +3114,7 @@ def process_module_assignment(self, lvals: List[Lvalue], rval: Expression,
# never create module alias except on initial var definition
elif lval.is_inferred_def:
lnode.kind = self.current_symbol_kind()
assert rnode.node is not None
lnode.node = rnode.node

def process__all__(self, s: AssignmentStmt) -> None:
Expand Down
24 changes: 24 additions & 0 deletions test-data/unit/fine-grained.test
Original file line number Diff line number Diff line change
Expand Up @@ -9160,3 +9160,27 @@ Data = Tuple[User, File]
[typing fixtures/typing-full.pyi]
[out]
==

[case testClassRedef]
# An issue involved serializing these caused crashes in the past

[file a.py]
class A:
pass

x = 0

[file a.py.2]
class A:
a = A()

x = '0'

[file b.py]
from a import A, x

class A: # type: ignore
pass

[out]
==
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy