8000 Original node wins in case of a redefinition (especially if it is a class) by ilevkivskyi · Pull Request #5565 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Original node wins in case of a redefinition (especially if it is a class) #5565

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 5 commits into from
Sep 4, 2018
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
Prev Previous commit
Next Next commit
Remove exception for classes and sync first pass
  • Loading branch information
Ivan Levkivskyi committed Sep 4, 2018
commit a698c55c7af3e880e556727052e1b15f0a19c072
3 changes: 1 addition & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -3288,8 +3288,7 @@ def add_symbol(self, name: str, node: SymbolTableNode,
self.locals[-1][name] = node
elif self.type:
existing = self.type.names.get(name)
if existing and isinstance(existing.node, TypeInfo) and existing.node != node.node:
# Classes can never be redefined
if existing and existing.node != node.node:
self.name_already_defined(name, context, existing)
return
self.type.names[name] = node
Expand Down
2 changes: 2 additions & 0 deletions mypy/semanal_pass1.py
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,7 @@ def add_symbol(self, name: str, node: SymbolTableNode,
if not (node.kind == MODULE_REF and
self.sem.locals[-1][name].node == node.node):
self.sem.name_already_defined(name, context, self.sem.locals[-1][name])
return
self.sem.locals[-1][name] = node
else:
assert self.sem.type is None # Pass 1 doesn't look inside classes
Expand All @@ -364,5 +365,6 @@ def add_symbol(self, name: str, node: SymbolTableNode,
ok = True
if not ok:
self.sem.name_already_defined(name, context, existing)
return
elif not existing:
self.sem.globals[name] = node
0