Skip to content

Fix crashes in class scoped imports #12023

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 33 commits into from
Feb 17, 2022
Merged
Changes from 1 commit
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
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
wow mypyc
  • Loading branch information
hauntsaninja committed Jan 20, 2022
commit a14004e56784c5cf63724c062e53229ee9426d87
6 changes: 4 additions & 2 deletions mypy/semanal.py
Original file line number Diff line number Diff line change
Expand Up @@ -4788,13 +4788,15 @@ def add_imported_symbol(self,
assert not module_hidden or not module_public

symbol_node: Optional[SymbolNode] = node.node
# I promise this type checks; I'm just making mypyc issues go away.
# mypyc is absolutely convinced that `symbol_node` narrows to a Var in the following,
# when it can also be a FuncBase.
symbol_node_any: Any = cast(Any, symbol_node)
if self.is_class_scope() and isinstance(symbol_node, (FuncBase, Var)):
# We construct a new node to represent this symbol and set its `info` attribute
# to `self.type`. Note that imports inside class scope do not produce methods, so
# in all cases constructing a Var gets us the assignment like behaviour we want.
existing = self.current_symbol_table().get(name)
# I promise this type checks; I'm just making mypyc issues go away.
symbol_node_any: Any = cast(Any, symbol_node)
if (
# The redefinition checks in `add_symbol_table_node` don't work for our
# constructed Var, so check for possible redefinitions here.
Expand Down