@@ -2853,6 +2853,7 @@ class is generic then it will be a type constructor of higher kind.
28532853 "fallback_to_any" ,
28542854 "meta_fallback_to_any" ,
28552855 "type_vars" ,
2856+ "has_type_var_default" ,
28562857 "has_param_spec_type" ,
28572858 "bases" ,
28582859 "_promote" ,
@@ -2957,6 +2958,9 @@ class is generic then it will be a type constructor of higher kind.
29572958 # Generic type variable names (full names)
29582959 type_vars : list [str ]
29592960
2961+ # Whether this class has a TypeVar with a default value
2962+ has_type_var_default : bool
2963+
29602964 # Whether this class has a ParamSpec type variable
29612965 has_param_spec_type : bool
29622966
@@ -3044,6 +3048,7 @@ def __init__(self, names: SymbolTable, defn: ClassDef, module_name: str) -> None
30443048 self .defn = defn
30453049 self .module_name = module_name
30463050 self .type_vars = []
3051+ self .has_type_var_default = False
30473052 self .has_param_spec_type = False
30483053 self .has_type_var_tuple_type = False
30493054 self .bases = []
@@ -3085,6 +3090,8 @@ def add_type_vars(self) -> None:
30853090 self .has_type_var_tuple_type = False
30863091 if self .defn .type_vars :
30873092 for i , vd in enumerate (self .defn .type_vars ):
3093+ if vd .has_default ():
3094+ self .has_type_var_default = True
30883095 if isinstance (vd , mypy .types .ParamSpecType ):
30893096 self .has_param_spec_type = True
30903097 if isinstance (vd , mypy .types .TypeVarTupleType ):
@@ -3280,6 +3287,7 @@ def serialize(self) -> JsonDict:
32803287 "defn" : self .defn .serialize (),
32813288 "abstract_attributes" : self .abstract_attributes ,
32823289 "type_vars" : self .type_vars ,
3290+ "has_type_var_default" : self .has_type_var_default ,
32833291 "has_param_spec_type" : self .has_param_spec_type ,
32843292 "bases" : [b .serialize () for b in self .bases ],
32853293 "mro" : [c .fullname for c in self .mro ],
@@ -3318,6 +3326,7 @@ def deserialize(cls, data: JsonDict) -> TypeInfo:
33183326 # TODO: Is there a reason to reconstruct ti.subtypes?
33193327 ti .abstract_attributes = [(attr [0 ], attr [1 ]) for attr in data ["abstract_attributes" ]]
33203328 ti .type_vars = data ["type_vars" ]
3329+ ti .has_type_var_default = data ["has_type_var_default" ]
33213330 ti .has_param_spec_type = data ["has_param_spec_type" ]
33223331 ti .bases = [mypy .types .Instance .deserialize (b ) for b in data ["bases" ]]
33233332 _promote = []
0 commit comments