22
22
from mypy .nodes import (
23
23
TypeInfo , Context , SymbolTableNode , Var , Expression ,
24
24
nongen_builtins , check_arg_names , check_arg_kinds , ARG_POS , ARG_NAMED ,
25
- ARG_OPT , ARG_NAMED_OPT , ARG_STAR , ARG_STAR2 , TypeVarExpr ,
25
+ ARG_OPT , ARG_NAMED_OPT , ARG_STAR , ARG_STAR2 , TypeVarExpr , TypeVarLikeExpr ,
26
26
TypeAlias , PlaceholderNode , SYMBOL_FUNCBASE_TYPES , Decorator , MypyFile
27
27
)
28
28
from mypy .typetraverser import TypeTraverserVisitor
@@ -792,13 +792,14 @@ def tvar_scope_frame(self) -> Iterator[None]:
792
792
self .tvar_scope = old_scope
793
793
794
794
def infer_type_variables (self ,
795
- type : CallableType ) -> List [Tuple [str , TypeVarExpr ]]:
795
+ type : CallableType ) -> List [Tuple [str , TypeVarLikeExpr ]]:
796
796
"""Return list of unique type variables referred to in a callable."""
797
797
names = [] # type: List[str]
798
- tvars = [] # type: List[TypeVarExpr ]
798
+ tvars = [] # type: List[TypeVarLikeExpr ]
799
799
for arg in type .arg_types :
800
- for name , tvar_expr in arg .accept (TypeVariableQuery (self .lookup_qualified ,
801
- self .tvar_scope )):
800
+ for name , tvar_expr in arg .accept (
801
+ TypeVarLikeQuery (self .lookup_qualified , self .tvar_scope )
802
+ ):
802
803
if name not in names :
803
804
names .append (name )
804
805
tvars .append (tvar_expr )
@@ -807,8 +808,8 @@ def infer_type_variables(self,
807
808
# functions in the return type belong to those functions, not the
808
809
# function we're currently analyzing.
809
810
for name , tvar_expr in type .ret_type .accept (
810
- TypeVariableQuery (self .lookup_qualified , self .tvar_scope ,
811
- include_callables = False ) ):
811
+ TypeVarLikeQuery (self .lookup_qualified , self .tvar_scope , include_callables = False )
812
+ ):
812
813
if name not in names :
813
814
names .append (name )
814
815
tvars .append (tvar_expr )
@@ -905,7 +906,7 @@ def tuple_type(self, items: List[Type]) -> TupleType:
905
906
return TupleType (items , fallback = self .named_type ('builtins.tuple' , [any_type ]))
906
907
907
908
908
- TypeVarList = List [Tuple [str , TypeVarExpr ]]
909
+ TypeVarLikeList = List [Tuple [str , TypeVarLikeExpr ]]
909
910
910
911
# Mypyc doesn't support callback protocols yet.
911
912
MsgCallback = Callable [[str , Context , DefaultNamedArg (Optional [ErrorCode ], 'code' )], None ]
@@ -1066,7 +1067,7 @@ def flatten_tvars(ll: Iterable[List[T]]) -> List[T]:
1066
1067
return remove_dups (chain .from_iterable (ll ))
1067
1068
1068
1069
1069
- class TypeVariableQuery (TypeQuery [TypeVarList ]):
1070
+ class TypeVarLikeQuery (TypeQuery [TypeVarLikeList ]):
1070
1071
1071
1072
def __init__ (self ,
1072
1073
lookup : Callable [[str , Context ], Optional [SymbolTableNode ]],
@@ -1087,12 +1088,12 @@ def _seems_like_callable(self, type: UnboundType) -> bool:
1087
1088
return True
1088
1089
return False
1089
1090
1090
- def visit_unbound_type (self , t : UnboundType ) -> TypeVarList :
1091
+ def visit_unbound_type (self , t : UnboundType ) -> TypeVarLikeList :
1091
1092
name = t .name
1092
1093
node = self .lookup (name , t )
1093
- if node and isinstance (node .node , TypeVarExpr ) and (
1094
+ if node and isinstance (node .node , TypeVarLikeExpr ) and (
1094
1095
self .include_bound_tvars or self .scope .get_binding (node ) is None ):
1095
- assert isinstance (node .node , TypeVarExpr )
1096
+ assert isinstance (node .node , TypeVarLikeExpr )
1096
1097
return [(name , node .node )]
1097
1098
elif not self .include_callables and self ._seems_like_callable (t ):
1098
1099
return []
@@ -1101,7 +1102,7 @@ def visit_unbound_type(self, t: UnboundType) -> TypeVarList:
1101
1102
else :
1102
1103
return super ().visit_unbound_type (t )
1103
1104
1104
- def visit_callable_type (self , t : CallableType ) -> TypeVarList :
1105
+ def visit_callable_type (self , t : CallableType ) -> TypeVarLikeList :
1105
1106
if self .include_callables :
1106
1107
return super ().visit_callable_type (t )
1107
1108
else :
0 commit comments