@@ -1183,20 +1183,22 @@ class TypeType(Type):
1183
1183
# a generic class instance, a union, Any, a type variable...
1184
1184
item = None # type: Type
1185
1185
1186
- # This class must be created using make method which may return either TypeType or UnionType.
1187
- # This is to ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]].
1188
1186
def __init__ (self , item : Union [Instance , AnyType , TypeVarType , TupleType , NoneTyp ,
1189
1187
CallableType ], * , line : int = - 1 , column : int = - 1 ) -> None :
1188
+ """To ensure Type[Union[A, B]] is always represented as Union[Type[A], Type[B]], item of
1189
+ type UnionType must be handled through make_normalized static method.
1190
+ """
1191
+
1190
1192
super ().__init__ (line , column )
1191
1193
if isinstance (item , CallableType ) and item .is_type_obj ():
1192
1194
self .item = item .fallback
1193
1195
else :
1194
1196
self .item = item
1195
1197
1196
1198
@staticmethod
1197
- def make (item : Type , * , line : int = - 1 , column : int = - 1 ) -> Type :
1199
+ def make_normalized (item : Type , * , line : int = - 1 , column : int = - 1 ) -> Type :
1198
1200
if isinstance (item , UnionType ):
1199
- return UnionType .make_union ([TypeType .make (union_item ) for union_item in item .items ],
1201
+ return UnionType .make_union ([TypeType .make_normalized (union_item ) for union_item in item .items ],
1200
1202
line = line , column = column )
1201
1203
elif isinstance (item , (Instance , AnyType , TypeVarType , TupleType , NoneTyp , CallableType )):
1202
1204
return TypeType (item , line = line , column = column )
@@ -1212,7 +1214,7 @@ def serialize(self) -> JsonDict:
1212
1214
@classmethod
1213
1215
def deserialize (cls , data : JsonDict ) -> Type :
1214
1216
assert data ['.class' ] == 'TypeType'
1215
- return TypeType .make (deserialize_type (data ['item' ]))
1217
+ return TypeType .make_normalized (deserialize_type (data ['item' ]))
1216
1218
1217
1219
1218
1220
#
@@ -1389,7 +1391,7 @@ def visit_overloaded(self, t: Overloaded) -> Type:
1389
1391
return Overloaded (items = items )
1390
1392
1391
1393
def visit_type_type (self , t : TypeType ) -> Type :
1392
- return TypeType .make (t .item .accept (self ), line = t .line , column = t .column )
1394
+ return TypeType .make_normalized (t .item .accept (self ), line = t .line , column = t .column )
1393
1395
1394
1396
1395
1397
class TypeStrVisitor (SyntheticTypeVisitor [str ]):
0 commit comments