88from collections import defaultdict
99from collections .abc import Iterator , Sequence
1010from enum import Enum , unique
11- from io import BytesIO
1211from typing import TYPE_CHECKING , Any , Callable , Final , Optional , TypeVar , Union , cast
1312from typing_extensions import TypeAlias as _TypeAlias , TypeGuard
1413
1817from mypy .cache import (
1918 LITERAL_COMPLEX ,
2019 LITERAL_NONE ,
21- OPT_NO ,
22- OPT_YES ,
20+ BytesIO ,
2321 read_bool ,
2422 read_float ,
2523 read_int ,
@@ -720,9 +718,9 @@ def write(self, data: BytesIO) -> None:
720718 mypy .types .write_type_opt (data , self .type )
721719 write_str (data , self ._fullname )
722720 if self .impl is None :
723- write_int (data , OPT_NO )
721+ write_bool (data , False )
724722 else :
725- write_int (data , OPT_YES )
723+ write_bool (data , True )
726724 self .impl .write (data )
727725 write_flags (data , self , FUNCBASE_FLAGS )
728726 write_str_opt (data , self .deprecated )
@@ -738,7 +736,7 @@ def read(cls, data: BytesIO) -> OverloadedFuncDef:
738736 assert isinstance (typ , mypy .types .ProperType )
739737 res .type = typ
740738 res ._fullname = read_str (data )
741- if read_int (data ) == OPT_YES :
739+ if read_bool (data ):
742740 res .impl = cast (OverloadPart , read_symbol (data ))
743741 # set line for empty overload items, as not set in __init__
744742 if len (res .items ) > 0 :
@@ -1035,9 +1033,9 @@ def write(self, data: BytesIO) -> None:
10351033 write_int_list (data , [int (ak .value ) for ak in self .arg_kinds ])
10361034 write_int (data , self .abstract_status )
10371035 if self .dataclass_transform_spec is None :
1038- write_int (data , OPT_NO )
1036+ write_bool (data , False )
10391037 else :
1040- write_int (data , OPT_YES )
1038+ write_bool (data , True )
10411039 self .dataclass_transform_spec .write (data )
10421040 write_str_opt (data , self .deprecated )
10431041 write_str_opt (data , self .original_first_arg )
@@ -1056,7 +1054,7 @@ def read(cls, data: BytesIO) -> FuncDef:
10561054 ret .arg_names = read_str_opt_list (data )
10571055 ret .arg_kinds = [ARG_KINDS [ak ] for ak in read_int_list (data )]
10581056 ret .abstract_status = read_int (data )
1059- if read_int (data ) == OPT_YES :
1057+ if read_bool (data ):
10601058 ret .dataclass_transform_spec = DataclassTransformSpec .read (data )
10611059 ret .deprecated = read_str_opt (data )
10621060 ret .original_first_arg = read_str_opt (data )
@@ -3931,16 +3929,16 @@ def write(self, data: BytesIO) -> None:
39313929 write_flags (data , self , TypeInfo .FLAGS )
39323930 write_str (data , json .dumps (self .metadata ))
39333931 if self .slots is None :
3934- write_int (data , OPT_NO )
3932+ write_bool (data , False )
39353933 else :
3936- write_int (data , OPT_YES )
3934+ write_bool (data , True )
39373935 write_str_list (data , sorted (self .slots ))
39383936 write_str_list (data , self .deletable_attributes )
39393937 mypy .types .write_type_opt (data , self .self_type )
39403938 if self .dataclass_transform_spec is None :
3941- write_int (data , OPT_NO )
3939+ write_bool (data , False )
39423940 else :
3943- write_int (data , OPT_YES )
3941+ write_bool (data , True )
39443942 self .dataclass_transform_spec .write (data )
39453943 write_str_opt (data , self .deprecated )
39463944
@@ -3974,30 +3972,32 @@ def read(cls, data: BytesIO) -> TypeInfo:
39743972 # rechecked, it can tell that the mro has changed.
39753973 ti ._mro_refs = read_str_list (data )
39763974 ti ._promote = cast (list [mypy .types .ProperType ], mypy .types .read_type_list (data ))
3977- if read_int (data ) == OPT_YES :
3975+ if read_bool (data ):
39783976 assert read_int (data ) == mypy .types .INSTANCE
39793977 ti .alt_promote = mypy .types .Instance .read (data )
3980- if read_int (data ) == OPT_YES :
3978+ if read_bool (data ):
39813979 assert read_int (data ) == mypy .types .INSTANCE
39823980 ti .declared_metaclass = mypy .types .Instance .read (data )
3983- if read_int (data ) == OPT_YES :
3981+ if read_bool (data ):
39843982 assert read_int (data ) == mypy .types .INSTANCE
39853983 ti .metaclass_type = mypy .types .Instance .read (data )
3986- if read_int (data ) == OPT_YES :
3984+ if read_bool (data ):
39873985 assert read_int (data ) == mypy .types .TUPLE_TYPE
39883986 ti .tuple_type = mypy .types .TupleType .read (data )
3989- if read_int (data ) == OPT_YES :
3987+ if read_bool (data ):
39903988 assert read_int (data ) == mypy .types .TYPED_DICT_TYPE
39913989 ti .typeddict_type = mypy .types .TypedDictType .read (data )
39923990 read_flags (data , ti , TypeInfo .FLAGS )
3993- ti .metadata = json .loads (read_str (data ))
3994- if read_int (data ) == OPT_YES :
3991+ metadata = read_str (data )
3992+ if metadata != "{}" :
3993+ ti .metadata = json .loads (metadata )
3994+ if read_bool (data ):
39953995 ti .slots = set (read_str_list (data ))
39963996 ti .deletable_attributes = read_str_list (data )
3997- if read_int (data ) == OPT_YES :
3997+ if read_bool (data ):
39983998 assert read_int (data ) == mypy .types .TYPE_VAR_TYPE
39993999 ti .self_type = mypy .types .TypeVarType .read (data )
4000- if read_int (data ) == OPT_YES :
4000+ if read_bool (data ):
40014001 ti .dataclass_transform_spec = DataclassTransformSpec .read (data )
40024002 ti .deprecated = read_str_opt (data )
40034003 return ti
0 commit comments