Skip to content

Commit 7bd60db

Browse files
author
hauntsaninja
committed
make mypyc issues go away
1 parent b93491a commit 7bd60db

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

mypy/semanal.py

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@
5252
from contextlib import contextmanager
5353

5454
from typing import (
55-
List, Dict, Set, Tuple, cast, TypeVar, Union, Optional, Callable, Iterator, Iterable
55+
Any, List, Dict, Set, Tuple, cast, TypeVar, Union, Optional, Callable, Iterator, Iterable
5656
)
5757
from typing_extensions import Final, TypeAlias as _TypeAlias
5858

@@ -4789,6 +4789,11 @@ def add_imported_symbol(self,
47894789
assert not module_hidden or not module_public
47904790

47914791
symbol_node: Optional[SymbolNode] = node.node
4792+
# I promise this type checks; I'm just making mypyc issues go away.
4793+
# mypyc is absolutely convinced that `symbol_node` narrows to a Var in the following,
4794+
# when it can also be a FuncBase.
4795+
# See also https://github.com/mypyc/mypyc/issues/892
4796+
symbol_node_any: Any = cast(Any, symbol_node)
47924797
if self.is_class_scope() and isinstance(symbol_node, (FuncBase, Var)):
47934798
# We construct a new node to represent this symbol and set its `info` attribute
47944799
# to `self.type`. Note that imports inside class scope do not produce methods, so
@@ -4799,14 +4804,14 @@ def add_imported_symbol(self,
47994804
# constructed Var, so check for possible redefinitions here.
48004805
existing is not None
48014806
and isinstance(existing.node, (FuncBase, Var))
4802-
and existing.type == symbol_node.type
4807+
and existing.type == symbol_node_any.type
48034808
):
48044809
symbol_node = existing.node
48054810
else:
48064811
if isinstance(symbol_node, Var):
4807-
symbol_node = Var(symbol_node.name, symbol_node.type)
4812+
symbol_node = Var(symbol_node_any.name, symbol_node_any.type)
48084813
elif isinstance(symbol_node, FuncBase):
4809-
symbol_node = copy.copy(symbol_node)
4814+
symbol_node = copy.copy(symbol_node_any)
48104815
else:
48114816
assert False
48124817
assert self.type is not None

0 commit comments

Comments
 (0)