@@ -1189,6 +1189,29 @@ def deserialize(cls, data: JsonDict) -> 'TypeType':
11891189 return TypeType (Type .deserialize (data ['item' ]))
11901190
11911191
1192+ class ClassVarType (Type ):
1193+ """The ClassVar[T] type.
1194+
1195+ In all typechecking scenarios, behaves like T.
1196+ """
1197+ item = None # type: Type
1198+
1199+ def __init__ (self , item : Type , * , line : int = - 1 , column : int = - 1 ) -> None :
1200+ super ().__init__ (line , column )
1201+ self .item = item
1202+
1203+ def accept (self , visitor : 'TypeVisitor[T]' ) -> T :
1204+ return visitor .visit_classvar_type (self )
1205+
1206+ def serialize (self ) -> JsonDict :
1207+ return {'.class' : 'ClassVarType' , 'item' : self .item .serialize ()}
1208+
1209+ @classmethod
1210+ def deserialize (cls , data : JsonDict ) -> 'TypeType' :
1211+ assert data ['.class' ] == 'ClassVarType'
1212+ return ClassVarType (Type .deserialize (data ['item' ]))
1213+
1214+
11921215#
11931216# Visitor-related classes
11941217#
@@ -1280,6 +1303,9 @@ def visit_ellipsis_type(self, t: EllipsisType) -> T:
12801303 def visit_type_type (self , t : TypeType ) -> T :
12811304 pass
12821305
1306+ def visit_classvar_type (self , t : ClassVarType ) -> T :
1307+ pass
1308+
12831309
12841310class TypeTranslator (TypeVisitor [Type ]):
12851311 """Identity type transformation.
@@ -1513,6 +1539,9 @@ def visit_ellipsis_type(self, t: EllipsisType) -> str:
15131539 def visit_type_type (self , t : TypeType ) -> str :
15141540 return 'Type[{}]' .format (t .item .accept (self ))
15151541
1542+ def visit_classvar_type (self , t : TypeType ) -> str :
1543+ return 'ClassVar[{}]' .format (t .item .accept (self ))
1544+
15161545 def list_str (self , a : List [Type ]) -> str :
15171546 """Convert items of an array to strings (pretty-print types)
15181547 and join the results with commas.
0 commit comments