Skip to content

Don't serialize redefined symbol nodes #7499

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 1 commit into from
Sep 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
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
8 changes: 2 additions & 6 deletions mypy/fixup.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,12 +57,8 @@ def visit_type_info(self, info: TypeInfo) -> None:
if info.metaclass_type:
info.metaclass_type.accept(self.type_fixer)
if info._mro_refs:
# If the class is a "-redefinition", then its
# reference to itself might be busted, so just use the
# info instead of looking up the first element. Ew.
info.mro = [info] + [
lookup_qualified_typeinfo(self.modules, name, self.allow_missing)
for name in info._mro_refs[1:]]
info.mro = [lookup_qualified_typeinfo(self.modules, name, self.allow_missing)
for name in info._mro_refs]
info._mro_refs = None
finally:
self.current_info = save_info
Expand Down
2 changes: 0 additions & 2 deletions mypy/nodes.py
Original file line number Diff line number Diff line change
Expand Up @@ -2996,8 +2996,6 @@ def serialize(self, prefix: str, name: str) -> JsonDict:
fullname = self.node.fullname()
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
5 changes: 5 additions & 0 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4245,6 +4245,11 @@ def add_redefinition(self,
redefinitions (such as e.g. variable redefined as a class).
"""
i = 1
# Don't serialize redefined nodes. They are likely to have
# busted internal references which can cause problems with
# serialization and they can't have any external references to
# them.
symbol.no_serialize = True
while True:
if i == 1:
new_name = '{}-redefinition'.format(name)
Expand Down
13 changes: 13 additions & 0 deletions test-data/unit/check-incremental.test
Original file line number Diff line number Diff line change
Expand Up @@ -5094,3 +5094,16 @@ tmp/a.py:4: error: Cannot determine type of 'foo'
[out2]
tmp/a.py:3: error: Cannot determine type of 'foo'
tmp/a.py:4: error: Cannot determine type of 'foo'

[case testRedefinitionClass]
import b
[file a.py]
from whatever import Foo # type: ignore

class Foo: # type: ignore
def f(self) -> None:
pass
[file b.py]
import a
[file b.py.2]
import a # a change
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