1616 CallableType , NoneType , ErasedType , DeletedType , TypeList , TypeVarDef , SyntheticTypeVisitor ,
1717 StarType , PartialType , EllipsisType , UninhabitedType , TypeType ,
1818 CallableArgument , TypeQuery , union_items , TypeOfAny , LiteralType , RawExpressionType ,
19- PlaceholderType , Overloaded , get_proper_type , TypeAliasType
19+ PlaceholderType , Overloaded , get_proper_type , TypeAliasType , TypeVarLikeDef
2020)
2121
2222from mypy .nodes import (
@@ -205,6 +205,7 @@ def visit_unbound_type_nonoptional(self, t: UnboundType, defining_literal: bool)
205205 ' to define generic alias' .format (t .name ), t )
206206 return AnyType (TypeOfAny .from_error )
207207 if isinstance (sym .node , TypeVarExpr ) and tvar_def is not None :
208+ assert isinstance (tvar_def , TypeVarDef )
208209 if len (t .args ) > 0 :
209210 self .fail ('Type variable "{}" used with arguments' .format (t .name ), t )
210211 return TypeVarType (tvar_def , t .line )
@@ -813,8 +814,9 @@ def infer_type_variables(self,
813814 tvars .append (tvar_expr )
814815 return list (zip (names , tvars ))
815816
816- def bind_function_type_variables (self ,
817- fun_type : CallableType , defn : Context ) -> List [TypeVarDef ]:
817+ def bind_function_type_variables (
818+ self , fun_type : CallableType , defn : Context
819+ ) -> Sequence [TypeVarLikeDef ]:
818820 """Find the type variables of the function type and bind them in our tvar_scope"""
819821 if fun_type .variables :
820822 for var in fun_type .variables :
@@ -828,7 +830,7 @@ def bind_function_type_variables(self,
828830 # Do not define a new type variable if already defined in scope.
829831 typevars = [(name , tvar ) for name , tvar in typevars
830832 if not self .is_defined_type_var (name , defn )]
831- defs = [] # type: List[TypeVarDef ]
833+ defs = [] # type: List[TypeVarLikeDef ]
832834 for name , tvar in typevars :
833835 if not self .tvar_scope .allow_binding (tvar .fullname ):
834836 self .fail ("Type variable '{}' is bound by an outer class" .format (name ), defn )
@@ -860,17 +862,22 @@ def anal_type(self, t: Type, nested: bool = True) -> Type:
860862 if nested :
861863 self .nesting_level -= 1
862864
863- def anal_var_defs (self , var_defs : List [TypeVarDef ]) -> List [TypeVarDef ]:
864- a = [] # type: List[TypeVarDef]
865- for vd in var_defs :
866- a .append (TypeVarDef (vd .name ,
867- vd .fullname ,
868- vd .id .raw_id ,
869- self .anal_array (vd .values ),
870- vd .upper_bound .accept (self ),
871- vd .variance ,
872- vd .line ))
873- return a
865+ def anal_var_def (self , var_def : TypeVarLikeDef ) -> TypeVarLikeDef :
866+ if isinstance (var_def , TypeVarDef ):
867+ return TypeVarDef (
868+ var_def .name ,
869+ var_def .fullname ,
870+ var_def .id .raw_id ,
871+ self .anal_array (var_def .values ),
872+ var_def .upper_bound .accept (self ),
873+ var_def .variance ,
874+ var_def .line
875+ )
876+ else :
877+ return var_def
878+
879+ def anal_var_defs (self , var_defs : Sequence [TypeVarLikeDef ]) -> List [TypeVarLikeDef ]:
880+ return [self .anal_var_def (vd ) for vd in var_defs ]
874881
875882 def named_type_with_normalized_str (self , fully_qualified_name : str ) -> Instance :
876883 """Does almost the same thing as `named_type`, except that we immediately
0 commit comments