@@ -195,20 +195,23 @@ def __init__(self, fp, magic_int, bytes_for_s, code_objects={}) -> None:
195195
196196 self .UNMARSHAL_DISPATCH_TABLE = UNMARSHAL_DISPATCH_TABLE
197197
198+ def read_float (self ) -> float :
199+ return unpack ("<d" , self .fp .read (8 ))[0 ]
200+
198201 def read_int16 (self ) -> int :
199- return int ( unpack ("<h" , self .fp .read (2 ))[0 ])
202+ return unpack ("<h" , self .fp .read (2 ))[0 ]
200203
201204 def read_int32 (self ) -> int :
202- return int ( unpack ("<i" , self .fp .read (4 ))[0 ])
205+ return unpack ("<i" , self .fp .read (4 ))[0 ]
203206
204207 def read_int64 (self ) -> int :
205- return int ( unpack ("<q" , self .fp .read (8 ))[0 ])
208+ return unpack ("<q" , self .fp .read (8 ))[0 ]
206209
207210 def read_slice (self , n : int ) -> bytes :
208211 return self .fp .read (n )
209212
210213 def read_uint32 (self ) -> int :
211- return int ( unpack ("<I" , self .fp .read (4 ))[0 ])
214+ return unpack ("<I" , self .fp .read (4 ))[0 ]
212215
213216 def load (self ):
214217 """
@@ -344,15 +347,15 @@ def t_int64(self, save_ref, bytes_for_s: bool = False):
344347 return obj
345348
346349 # float - Seems not in use after Python 2.4
347- def t_float (self , save_ref , bytes_for_s : bool = False ):
350+ def t_float (self , save_ref , bytes_for_s : bool = False ) -> float :
348351 strsize = unpack ("B" , self .fp .read (1 ))[0 ]
349352 s = self .fp .read (strsize )
350353 return self .r_ref (float (s ), save_ref )
351354
352- def t_binary_float (self , save_ref , bytes_for_s : bool = False ):
353- return self .r_ref (float ( unpack ( "<d" , self .fp . read ( 8 ))[ 0 ] ), save_ref )
355+ def t_binary_float (self , save_ref , bytes_for_s : bool = False ) -> float :
356+ return self .r_ref (self .read_float ( ), save_ref )
354357
355- def t_complex (self , save_ref , bytes_for_s : bool = False ):
358+ def t_complex (self , save_ref , bytes_for_s : bool = False ) -> complex :
356359 def unpack_pre_24 () -> float :
357360 return float (self .fp .read (unpack ("B" , self .fp .read (1 ))[0 ]))
358361
@@ -365,10 +368,10 @@ def unpack_newer() -> float:
365368 imag = get_float ()
366369 return self .r_ref (complex (real , imag ), save_ref )
367370
368- def t_binary_complex (self , save_ref , bytes_for_s : bool = False ):
371+ def t_binary_complex (self , save_ref , bytes_for_s : bool = False ) -> complex :
369372 # binary complex
370- real = unpack ( "<d" , self .fp . read ( 8 ))[ 0 ]
371- imag = unpack ( "<d" , self .fp . read ( 8 ))[ 0 ]
373+ real = self .read_float ()
374+ imag = self .read_float ()
372375 return self .r_ref (complex (real , imag ), save_ref )
373376
374377 def t_string (self , save_ref , bytes_for_s : bool ):
@@ -476,15 +479,15 @@ def t_frozenset(self, save_ref, bytes_for_s: bool = False):
476479 self .collection_order [final_frozenset ] = tuple (collection )
477480 return self .r_ref_insert (final_frozenset , i )
478481
479- def t_set (self , save_ref , bytes_for_s : bool = False ):
482+ def t_set (self , save_ref , bytes_for_s : bool = False ) -> set :
480483 setsize = self .read_uint32 ()
481484 ret , i = self .r_ref_reserve (tuple (), save_ref )
482485 while setsize > 0 :
483486 ret += (self .r_object (bytes_for_s = bytes_for_s ),)
484487 setsize -= 1
485488 return self .r_ref_insert (set (ret ), i )
486489
487- def t_dict (self , save_ref , bytes_for_s : bool = False ):
490+ def t_dict (self , save_ref , bytes_for_s : bool = False ) -> dict :
488491 ret = self .r_ref (dict (), save_ref )
489492 # dictionary
490493 while True :
0 commit comments