@@ -67,7 +67,8 @@ def read(cls, mode: Mode) -> Self:
6767
6868 with cache_file .open ("rb" ) as fobj :
6969 try :
70- file_data : Dict [str , FileData ] = pickle .load (fobj )
70+ data : Dict [str , Tuple [float , int , str ]] = pickle .load (fobj )
71+ file_data = {k : FileData (* v ) for k , v in data .items ()}
7172 except (pickle .UnpicklingError , ValueError , IndexError ):
7273 return cls (mode , cache_file )
7374
@@ -129,7 +130,12 @@ def write(self, sources: Iterable[Path]) -> None:
129130 with tempfile .NamedTemporaryFile (
130131 dir = str (self .cache_file .parent ), delete = False
131132 ) as f :
132- pickle .dump (self .file_data , f , protocol = 4 )
133+ # We store raw tuples in the cache because pickling NamedTuples
134+ # doesn't work with mypyc on Python 3.8, and because it's faster.
135+ data : Dict [str , Tuple [float , int , str ]] = {
136+ k : (* v ,) for k , v in self .file_data .items ()
137+ }
138+ pickle .dump (data , f , protocol = 4 )
133139 os .replace (f .name , self .cache_file )
134140 except OSError :
135141 pass
0 commit comments