2222# THE SOFTWARE.
2323
2424import os
25+ from pathlib import Path
2526import stat
2627from itertools import islice , chain
27- from typing import Iterable , Optional , List , TextIO
28+ from typing import Iterable , Optional , List , TextIO , Union
2829
2930from .translations import _
3031from .filelock import FileLock
@@ -190,9 +191,9 @@ def reset(self) -> None:
190191 self .index = 0
191192 self .saved_line = ""
192193
193- def load (self , filename : str , encoding : str ) -> None :
194+ def load (self , filename : Path , encoding : str ) -> None :
194195 with open (filename , encoding = encoding , errors = "ignore" ) as hfile :
195- with FileLock (hfile , filename = filename ):
196+ with FileLock (hfile , filename = str ( filename ) ):
196197 self .entries = self .load_from (hfile )
197198
198199 def load_from (self , fd : TextIO ) -> List [str ]:
@@ -201,14 +202,14 @@ def load_from(self, fd: TextIO) -> List[str]:
201202 self .append_to (entries , line )
202203 return entries if len (entries ) else ["" ]
203204
204- def save (self , filename : str , encoding : str , lines : int = 0 ) -> None :
205+ def save (self , filename : Path , encoding : str , lines : int = 0 ) -> None :
205206 fd = os .open (
206207 filename ,
207208 os .O_WRONLY | os .O_CREAT | os .O_TRUNC ,
208209 stat .S_IRUSR | stat .S_IWUSR ,
209210 )
210211 with open (fd , "w" , encoding = encoding , errors = "ignore" ) as hfile :
211- with FileLock (hfile , filename = filename ):
212+ with FileLock (hfile , filename = str ( filename ) ):
212213 self .save_to (hfile , self .entries , lines )
213214
214215 def save_to (
@@ -221,7 +222,7 @@ def save_to(
221222 fd .write ("\n " )
222223
223224 def append_reload_and_write (
224- self , s : str , filename : str , encoding : str
225+ self , s : str , filename : Path , encoding : str
225226 ) -> None :
226227 if not self .hist_size :
227228 return self .append (s )
@@ -233,7 +234,7 @@ def append_reload_and_write(
233234 stat .S_IRUSR | stat .S_IWUSR ,
234235 )
235236 with open (fd , "a+" , encoding = encoding , errors = "ignore" ) as hfile :
236- with FileLock (hfile , filename = filename ):
237+ with FileLock (hfile , filename = str ( filename ) ):
237238 # read entries
238239 hfile .seek (0 , os .SEEK_SET )
239240 entries = self .load_from (hfile )
0 commit comments