@@ -299,7 +299,7 @@ def dump_collection(self, type_code: str, bag: Union[frozenset, set, dict]) -> N
299299 for each in collection :
300300 self .dump (each )
301301
302- def dump_complex (self , x ) -> None :
302+ def dump_complex (self , x , _ ) -> None :
303303 write = self ._write
304304 write (TYPE_COMPLEX )
305305 s = repr (x .real )
@@ -551,16 +551,20 @@ def dump_stopiter(self, x) -> None:
551551
552552 dispatch [type (StopIteration )] = dump_stopiter
553553
554- def dump_string (self , x , flag_ref : int = 0 ) -> None :
554+ def dump_string (self , s , flag_ref : int = 0 ) -> None :
555555 # Python 3.11 seems to add the object ref flag bit for strings.
556- type_string = (
557- TYPE_STRING
558- if self .python_version < (3 , 11 )
559- else chr (ord (TYPE_STRING ) | flag_ref )
560- )
561- self ._write (type_string )
562- self .w_long (len (x ))
563- self ._write (x )
556+ if self .python_version >= (3 , 11 ):
557+ type_code = chr (ord (TYPE_STRING ) | flag_ref )
558+ if (3 , 0 ) <= self .python_version < (3 , 11 ):
559+ type_code = TYPE_STRING
560+ else :
561+ # Python 2.x.
562+ # FIXME: save string somewhere if it isn't in string table.
563+ type_code = TYPE_INTERNED if s in self .reference_objects else TYPE_STRING
564+
565+ self ._write (type_code )
566+ self .w_long (len (s ))
567+ self ._write (s )
564568
565569 dispatch [bytes ] = dump_string
566570 dispatch [bytearray ] = dump_string
@@ -585,8 +589,10 @@ def dump_tuple(self, tuple_object: tuple, flag_ref: int = 0) -> None:
585589 def dump_unicode (self , s , flag_ref : int = 0 ) -> None :
586590 if self .python_version < (2 , 0 ):
587591 type_code = TYPE_STRING
588- elif (2 , 0 ) <= self .python_version <= (3 , 0 ):
589- type_code = TYPE_INTERNED
592+ elif (2 , 0 ) <= self .python_version < (3 , 0 ):
593+ # FIXME: probably need to save string somewhere
594+ # if it isn't in string table.
595+ type_code = TYPE_INTERNED if s in self .reference_objects else TYPE_STRING
590596 else :
591597 type_code = TYPE_UNICODE
592598
0 commit comments