@@ -728,16 +728,14 @@ def write(self, data: BytesIO) -> None:
728728
729729 @classmethod
730730 def read (cls , data : BytesIO ) -> OverloadedFuncDef :
731- res = OverloadedFuncDef (
732- [cast (OverloadPart , read_symbol (data )) for _ in range (read_int (data ))]
733- )
731+ res = OverloadedFuncDef ([read_overload_part (data ) for _ in range (read_int (data ))])
734732 typ = mypy .types .read_type_opt (data )
735733 if typ is not None :
736734 assert isinstance (typ , mypy .types .ProperType )
737735 res .type = typ
738736 res ._fullname = read_str (data )
739737 if read_bool (data ):
740- res .impl = cast ( OverloadPart , read_symbol ( data ) )
738+ res .impl = read_overload_part ( data )
741739 # set line for empty overload items, as not set in __init__
742740 if len (res .items ) > 0 :
743741 res .set_line (res .impl .line )
@@ -1042,12 +1040,11 @@ def write(self, data: BytesIO) -> None:
10421040
10431041 @classmethod
10441042 def read (cls , data : BytesIO ) -> FuncDef :
1045- ret = FuncDef (
1046- read_str (data ),
1047- [],
1048- Block ([]),
1049- cast ("mypy.types.FunctionLike | None" , mypy .types .read_type_opt (data )),
1050- )
1043+ name = read_str (data )
1044+ typ : mypy .types .FunctionLike | None = None
1045+ if read_bool (data ):
1046+ typ = mypy .types .read_function_like (data )
1047+ ret = FuncDef (name , [], Block ([]), typ )
10511048 ret ._fullname = read_str (data )
10521049 read_flags (data , ret , FUNCDEF_FLAGS )
10531050 # NOTE: ret.info is set in the fixup phase.
@@ -1340,14 +1337,12 @@ def write(self, data: BytesIO) -> None:
13401337 @classmethod
13411338 def read (cls , data : BytesIO ) -> Var :
13421339 name = read_str (data )
1343- type = mypy .types .read_type_opt (data )
1344- setter_type = mypy .types .read_type_opt (data )
1345- v = Var (name , type )
1346- assert (
1347- setter_type is None
1348- or isinstance (setter_type , mypy .types .ProperType )
1349- and isinstance (setter_type , mypy .types .CallableType )
1350- )
1340+ typ = mypy .types .read_type_opt (data )
1341+ v = Var (name , typ )
1342+ setter_type : mypy .types .CallableType | None = None
1343+ if read_bool (data ):
1344+ assert read_int (data ) == mypy .types .CALLABLE_TYPE
1345+ setter_type = mypy .types .CallableType .read (data )
13511346 v .setter_type = setter_type
13521347 v .is_ready = False # Override True default set in __init__
13531348 v ._fullname = read_str (data )
@@ -1480,7 +1475,7 @@ def read(cls, data: BytesIO) -> ClassDef:
14801475 res = ClassDef (
14811476 read_str (data ),
14821477 Block ([]),
1483- cast ( list [mypy .types .TypeVarLikeType ], mypy . types . read_type_list ( data )),
1478+ [mypy .types .read_type_var_like ( data ) for _ in range ( read_int ( data ))] ,
14841479 )
14851480 res .fullname = read_str (data )
14861481 return res
@@ -4275,32 +4270,26 @@ def write(self, data: BytesIO) -> None:
42754270 write_str (data , self ._fullname )
42764271 self .target .write (data )
42774272 mypy .types .write_type_list (data , self .alias_tvars )
4278- write_bool (data , self .no_args )
4279- write_bool (data , self .normalized )
42804273 write_int (data , self .line )
42814274 write_int (data , self .column )
4275+ write_bool (data , self .no_args )
4276+ write_bool (data , self .normalized )
42824277 write_bool (data , self .python_3_12_type_alias )
42834278
42844279 @classmethod
42854280 def read (cls , data : BytesIO ) -> TypeAlias :
42864281 fullname = read_str (data )
42874282 target = mypy .types .read_type (data )
4288- alias_tvars = mypy .types .read_type_list (data )
4289- assert all (isinstance (t , mypy .types .TypeVarLikeType ) for t in alias_tvars )
4290- no_args = read_bool (data )
4291- normalized = read_bool (data )
4292- line = read_int (data )
4293- column = read_int (data )
4294- python_3_12_type_alias = read_bool (data )
4295- return cls (
4283+ alias_tvars = [mypy .types .read_type_var_like (data ) for _ in range (read_int (data ))]
4284+ return TypeAlias (
42964285 target ,
42974286 fullname ,
4298- line ,
4299- column ,
4300- alias_tvars = cast ( list [ mypy . types . TypeVarLikeType ], alias_tvars ) ,
4301- no_args = no_args ,
4302- normalized = normalized ,
4303- python_3_12_type_alias = python_3_12_type_alias ,
4287+ read_int ( data ) ,
4288+ read_int ( data ) ,
4289+ alias_tvars = alias_tvars ,
4290+ no_args = read_bool ( data ) ,
4291+ normalized = read_bool ( data ) ,
4292+ python_3_12_type_alias = read_bool ( data ) ,
43044293 )
43054294
43064295
@@ -4562,7 +4551,7 @@ def deserialize(cls, data: JsonDict) -> SymbolTableNode:
45624551 return stnode
45634552
45644553 def write (self , data : BytesIO , prefix : str , name : str ) -> None :
4565- write_str (data , node_kinds [ self .kind ] )
4554+ write_int (data , self .kind )
45664555 write_bool (data , self .module_hidden )
45674556 write_bool (data , self .module_public )
45684557 write_bool (data , self .implicit )
@@ -4592,8 +4581,7 @@ def write(self, data: BytesIO, prefix: str, name: str) -> None:
45924581
45934582 @classmethod
45944583 def read (cls , data : BytesIO ) -> SymbolTableNode :
4595- kind = inverse_node_kinds [read_str (data )]
4596- sym = SymbolTableNode (kind , None )
4584+ sym = SymbolTableNode (read_int (data ), None )
45974585 sym .module_hidden = read_bool (data )
45984586 sym .module_public = read_bool (data )
45994587 sym .implicit = read_bool (data )
@@ -4912,3 +4900,12 @@ def read_symbol(data: BytesIO) -> mypy.nodes.SymbolNode:
49124900 if marker == TYPE_VAR_TUPLE_EXPR :
49134901 return mypy .nodes .TypeVarTupleExpr .read (data )
49144902 assert False , f"Unknown symbol marker { marker } "
4903+
4904+
4905+ def read_overload_part (data : BytesIO ) -> OverloadPart :
4906+ marker = read_int (data )
4907+ if marker == DECORATOR :
4908+ return Decorator .read (data )
4909+ if marker == FUNC_DEF :
4910+ return FuncDef .read (data )
4911+ assert False , f"Invalid marker for an OverloadPart { marker } "
0 commit comments