52
52
from contextlib import contextmanager
53
53
54
54
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
56
56
)
57
57
from typing_extensions import Final , TypeAlias as _TypeAlias
58
58
@@ -4789,6 +4789,11 @@ def add_imported_symbol(self,
4789
4789
assert not module_hidden or not module_public
4790
4790
4791
4791
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 )
4792
4797
if self .is_class_scope () and isinstance (symbol_node , (FuncBase , Var )):
4793
4798
# We construct a new node to represent this symbol and set its `info` attribute
4794
4799
# to `self.type`. Note that imports inside class scope do not produce methods, so
@@ -4799,14 +4804,14 @@ def add_imported_symbol(self,
4799
4804
# constructed Var, so check for possible redefinitions here.
4800
4805
existing is not None
4801
4806
and isinstance (existing .node , (FuncBase , Var ))
4802
- and existing .type == symbol_node .type
4807
+ and existing .type == symbol_node_any .type
4803
4808
):
4804
4809
symbol_node = existing .node
4805
4810
else :
4806
4811
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 )
4808
4813
elif isinstance (symbol_node , FuncBase ):
4809
- symbol_node = copy .copy (symbol_node )
4814
+ symbol_node = copy .copy (symbol_node_any )
4810
4815
else :
4811
4816
assert False
4812
4817
assert self .type is not None
0 commit comments