28
28
read_str_list ,
29
29
read_str_opt ,
30
30
read_str_opt_list ,
31
+ read_tag ,
31
32
write_bool ,
32
33
write_int ,
33
34
write_int_list ,
37
38
write_str_list ,
38
39
write_str_opt ,
39
40
write_str_opt_list ,
41
+ write_tag ,
40
42
)
41
43
from mypy .options import Options
42
44
from mypy .util import is_sunder , is_typeshed_file , short_type
@@ -417,7 +419,7 @@ def deserialize(cls, data: JsonDict) -> MypyFile:
417
419
return tree
418
420
419
421
def write (self , data : Buffer ) -> None :
420
- write_int (data , MYPY_FILE )
422
+ write_tag (data , MYPY_FILE )
421
423
write_str (data , self ._fullname )
422
424
self .names .write (data , self ._fullname )
423
425
write_bool (data , self .is_stub )
@@ -427,7 +429,7 @@ def write(self, data: Buffer) -> None:
427
429
428
430
@classmethod
429
431
def read (cls , data : Buffer ) -> MypyFile :
430
- assert read_int (data ) == MYPY_FILE
432
+ assert read_tag (data ) == MYPY_FILE
431
433
tree = MypyFile ([], [])
432
434
tree ._fullname = read_str (data )
433
435
tree .names = SymbolTable .read (data )
@@ -711,7 +713,7 @@ def deserialize(cls, data: JsonDict) -> OverloadedFuncDef:
711
713
return res
712
714
713
715
def write (self , data : Buffer ) -> None :
714
- write_int (data , OVERLOADED_FUNC_DEF )
716
+ write_tag (data , OVERLOADED_FUNC_DEF )
715
717
write_int (data , len (self .items ))
716
718
for item in self .items :
717
719
item .write (data )
@@ -1022,7 +1024,7 @@ def deserialize(cls, data: JsonDict) -> FuncDef:
1022
1024
return ret
1023
1025
1024
1026
def write (self , data : Buffer ) -> None :
1025
- write_int (data , FUNC_DEF )
1027
+ write_tag (data , FUNC_DEF )
1026
1028
write_str (data , self ._name )
1027
1029
mypy .types .write_type_opt (data , self .type )
1028
1030
write_str (data , self ._fullname )
@@ -1134,16 +1136,16 @@ def deserialize(cls, data: JsonDict) -> Decorator:
1134
1136
return dec
1135
1137
1136
1138
def write (self , data : Buffer ) -> None :
1137
- write_int (data , DECORATOR )
1139
+ write_tag (data , DECORATOR )
1138
1140
self .func .write (data )
1139
1141
self .var .write (data )
1140
1142
write_bool (data , self .is_overload )
1141
1143
1142
1144
@classmethod
1143
1145
def read (cls , data : Buffer ) -> Decorator :
1144
- assert read_int (data ) == FUNC_DEF
1146
+ assert read_tag (data ) == FUNC_DEF
1145
1147
func = FuncDef .read (data )
1146
- assert read_int (data ) == VAR
1148
+ assert read_tag (data ) == VAR
1147
1149
var = Var .read (data )
1148
1150
dec = Decorator (func , [], var )
1149
1151
dec .is_overload = read_bool (data )
@@ -1326,7 +1328,7 @@ def deserialize(cls, data: JsonDict) -> Var:
1326
1328
return v
1327
1329
1328
1330
def write (self , data : Buffer ) -> None :
1329
- write_int (data , VAR )
1331
+ write_tag (data , VAR )
1330
1332
write_str (data , self ._name )
1331
1333
mypy .types .write_type_opt (data , self .type )
1332
1334
mypy .types .write_type_opt (data , self .setter_type )
@@ -1341,13 +1343,13 @@ def read(cls, data: Buffer) -> Var:
1341
1343
v = Var (name , typ )
1342
1344
setter_type : mypy .types .CallableType | None = None
1343
1345
if read_bool (data ):
1344
- assert read_int (data ) == mypy .types .CALLABLE_TYPE
1346
+ assert read_tag (data ) == mypy .types .CALLABLE_TYPE
1345
1347
setter_type = mypy .types .CallableType .read (data )
1346
1348
v .setter_type = setter_type
1347
1349
v .is_ready = False # Override True default set in __init__
1348
1350
v ._fullname = read_str (data )
1349
1351
read_flags (data , v , VAR_FLAGS )
1350
- marker = read_int (data )
1352
+ marker = read_tag (data )
1351
1353
if marker == LITERAL_COMPLEX :
1352
1354
v .final_value = complex (read_float (data ), read_float (data ))
1353
1355
elif marker != LITERAL_NONE :
@@ -1465,7 +1467,7 @@ def deserialize(cls, data: JsonDict) -> ClassDef:
1465
1467
return res
1466
1468
1467
1469
def write (self , data : Buffer ) -> None :
1468
- write_int (data , CLASS_DEF )
1470
+ write_tag (data , CLASS_DEF )
1469
1471
write_str (data , self .name )
1470
1472
mypy .types .write_type_list (data , self .type_vars )
1471
1473
write_str (data , self .fullname )
@@ -2898,7 +2900,7 @@ def deserialize(cls, data: JsonDict) -> TypeVarExpr:
2898
2900
)
2899
2901
2900
2902
def write (self , data : Buffer ) -> None :
2901
- write_int (data , TYPE_VAR_EXPR )
2903
+ write_tag (data , TYPE_VAR_EXPR )
2902
2904
write_str (data , self ._name )
2903
2905
write_str (data , self ._fullname )
2904
2906
mypy .types .write_type_list (data , self .values )
@@ -2948,7 +2950,7 @@ def deserialize(cls, data: JsonDict) -> ParamSpecExpr:
2948
2950
)
2949
2951
2950
2952
def write (self , data : Buffer ) -> None :
2951
- write_int (data , PARAM_SPEC_EXPR )
2953
+ write_tag (data , PARAM_SPEC_EXPR )
2952
2954
write_str (data , self ._name )
2953
2955
write_str (data , self ._fullname )
2954
2956
self .upper_bound .write (data )
@@ -3016,7 +3018,7 @@ def deserialize(cls, data: JsonDict) -> TypeVarTupleExpr:
3016
3018
)
3017
3019
3018
3020
def write (self , data : Buffer ) -> None :
3019
- write_int (data , TYPE_VAR_TUPLE_EXPR )
3021
+ write_tag (data , TYPE_VAR_TUPLE_EXPR )
3020
3022
self .tuple_fallback .write (data )
3021
3023
write_str (data , self ._name )
3022
3024
write_str (data , self ._fullname )
@@ -3026,7 +3028,7 @@ def write(self, data: Buffer) -> None:
3026
3028
3027
3029
@classmethod
3028
3030
def read (cls , data : Buffer ) -> TypeVarTupleExpr :
3029
- assert read_int (data ) == mypy .types .INSTANCE
3031
+ assert read_tag (data ) == mypy .types .INSTANCE
3030
3032
fallback = mypy .types .Instance .read (data )
3031
3033
return TypeVarTupleExpr (
3032
3034
read_str (data ),
@@ -3908,7 +3910,7 @@ def deserialize(cls, data: JsonDict) -> TypeInfo:
3908
3910
return ti
3909
3911
3910
3912
def write (self , data : Buffer ) -> None :
3911
- write_int (data , TYPE_INFO )
3913
+ write_tag (data , TYPE_INFO )
3912
3914
self .names .write (data , self .fullname )
3913
3915
self .defn .write (data )
3914
3916
write_str (data , self .module_name )
@@ -3944,7 +3946,7 @@ def write(self, data: Buffer) -> None:
3944
3946
@classmethod
3945
3947
def read (cls , data : Buffer ) -> TypeInfo :
3946
3948
names = SymbolTable .read (data )
3947
- assert read_int (data ) == CLASS_DEF
3949
+ assert read_tag (data ) == CLASS_DEF
3948
3950
defn = ClassDef .read (data )
3949
3951
module_name = read_str (data )
3950
3952
ti = TypeInfo (names , defn , module_name )
@@ -3954,10 +3956,9 @@ def read(cls, data: Buffer) -> TypeInfo:
3954
3956
ti .abstract_attributes = list (zip (attrs , statuses ))
3955
3957
ti .type_vars = read_str_list (data )
3956
3958
ti .has_param_spec_type = read_bool (data )
3957
- num_bases = read_int (data )
3958
3959
ti .bases = []
3959
- for _ in range (num_bases ):
3960
- assert read_int (data ) == mypy .types .INSTANCE
3960
+ for _ in range (read_int ( data ) ):
3961
+ assert read_tag (data ) == mypy .types .INSTANCE
3961
3962
ti .bases .append (mypy .types .Instance .read (data ))
3962
3963
# NOTE: ti.mro will be set in the fixup phase based on these
3963
3964
# names. The reason we need to store the mro instead of just
@@ -3972,19 +3973,19 @@ def read(cls, data: Buffer) -> TypeInfo:
3972
3973
ti ._mro_refs = read_str_list (data )
3973
3974
ti ._promote = cast (list [mypy .types .ProperType ], mypy .types .read_type_list (data ))
3974
3975
if read_bool (data ):
3975
- assert read_int (data ) == mypy .types .INSTANCE
3976
+ assert read_tag (data ) == mypy .types .INSTANCE
3976
3977
ti .alt_promote = mypy .types .Instance .read (data )
3977
3978
if read_bool (data ):
3978
- assert read_int (data ) == mypy .types .INSTANCE
3979
+ assert read_tag (data ) == mypy .types .INSTANCE
3979
3980
ti .declared_metaclass = mypy .types .Instance .read (data )
3980
3981
if read_bool (data ):
3981
- assert read_int (data ) == mypy .types .INSTANCE
3982
+ assert read_tag (data ) == mypy .types .INSTANCE
3982
3983
ti .metaclass_type = mypy .types .Instance .read (data )
3983
3984
if read_bool (data ):
3984
- assert read_int (data ) == mypy .types .TUPLE_TYPE
3985
+ assert read_tag (data ) == mypy .types .TUPLE_TYPE
3985
3986
ti .tuple_type = mypy .types .TupleType .read (data )
3986
3987
if read_bool (data ):
3987
- assert read_int (data ) == mypy .types .TYPED_DICT_TYPE
3988
+ assert read_tag (data ) == mypy .types .TYPED_DICT_TYPE
3988
3989
ti .typeddict_type = mypy .types .TypedDictType .read (data )
3989
3990
read_flags (data , ti , TypeInfo .FLAGS )
3990
3991
metadata = read_str (data )
@@ -3994,7 +3995,7 @@ def read(cls, data: Buffer) -> TypeInfo:
3994
3995
ti .slots = set (read_str_list (data ))
3995
3996
ti .deletable_attributes = read_str_list (data )
3996
3997
if read_bool (data ):
3997
- assert read_int (data ) == mypy .types .TYPE_VAR_TYPE
3998
+ assert read_tag (data ) == mypy .types .TYPE_VAR_TYPE
3998
3999
ti .self_type = mypy .types .TypeVarType .read (data )
3999
4000
if read_bool (data ):
4000
4001
ti .dataclass_transform_spec = DataclassTransformSpec .read (data )
@@ -4270,7 +4271,7 @@ def deserialize(cls, data: JsonDict) -> TypeAlias:
4270
4271
)
4271
4272
4272
4273
def write (self , data : Buffer ) -> None :
4273
- write_int (data , TYPE_ALIAS )
4274
+ write_tag (data , TYPE_ALIAS )
4274
4275
write_str (data , self ._fullname )
4275
4276
self .target .write (data )
4276
4277
mypy .types .write_type_list (data , self .alias_tvars )
@@ -4890,33 +4891,33 @@ def local_definitions(
4890
4891
4891
4892
4892
4893
def read_symbol (data : Buffer ) -> mypy .nodes .SymbolNode :
4893
- marker = read_int (data )
4894
+ tag = read_tag (data )
4894
4895
# The branches here are ordered manually by type "popularity".
4895
- if marker == VAR :
4896
+ if tag == VAR :
4896
4897
return mypy .nodes .Var .read (data )
4897
- if marker == FUNC_DEF :
4898
+ if tag == FUNC_DEF :
4898
4899
return mypy .nodes .FuncDef .read (data )
4899
- if marker == DECORATOR :
4900
+ if tag == DECORATOR :
4900
4901
return mypy .nodes .Decorator .read (data )
4901
- if marker == TYPE_INFO :
4902
+ if tag == TYPE_INFO :
4902
4903
return mypy .nodes .TypeInfo .read (data )
4903
- if marker == OVERLOADED_FUNC_DEF :
4904
+ if tag == OVERLOADED_FUNC_DEF :
4904
4905
return mypy .nodes .OverloadedFuncDef .read (data )
4905
- if marker == TYPE_VAR_EXPR :
4906
+ if tag == TYPE_VAR_EXPR :
4906
4907
return mypy .nodes .TypeVarExpr .read (data )
4907
- if marker == TYPE_ALIAS :
4908
+ if tag == TYPE_ALIAS :
4908
4909
return mypy .nodes .TypeAlias .read (data )
4909
- if marker == PARAM_SPEC_EXPR :
4910
+ if tag == PARAM_SPEC_EXPR :
4910
4911
return mypy .nodes .ParamSpecExpr .read (data )
4911
- if marker == TYPE_VAR_TUPLE_EXPR :
4912
+ if tag == TYPE_VAR_TUPLE_EXPR :
4912
4913
return mypy .nodes .TypeVarTupleExpr .read (data )
4913
- assert False , f"Unknown symbol marker { marker } "
4914
+ assert False , f"Unknown symbol tag { tag } "
4914
4915
4915
4916
4916
4917
def read_overload_part (data : Buffer ) -> OverloadPart :
4917
- marker = read_int (data )
4918
- if marker == DECORATOR :
4918
+ tag = read_tag (data )
4919
+ if tag == DECORATOR :
4919
4920
return Decorator .read (data )
4920
- if marker == FUNC_DEF :
4921
+ if tag == FUNC_DEF :
4921
4922
return FuncDef .read (data )
4922
- assert False , f"Invalid marker for an OverloadPart { marker } "
4923
+ assert False , f"Invalid tag for an OverloadPart { tag } "
0 commit comments