Skip to content

Commit cc3bac7

Browse files
committed
Change filenames in History to Path
1 parent b86de33 commit cc3bac7

File tree

3 files changed

+12
-11
lines changed

3 files changed

+12
-11
lines changed

bpython/history.py

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,10 @@
2222
# THE SOFTWARE.
2323

2424
import os
25+
from pathlib import Path
2526
import stat
2627
from itertools import islice, chain
27-
from typing import Iterable, Optional, List, TextIO
28+
from typing import Iterable, Optional, List, TextIO, Union
2829

2930
from .translations import _
3031
from .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)

bpython/repl.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -520,7 +520,7 @@ def __init__(self, interp: Interpreter, config: Config):
520520
if self.config.hist_file.exists():
521521
try:
522522
self.rl_history.load(
523-
str(self.config.hist_file),
523+
self.config.hist_file,
524524
getpreferredencoding() or "ascii",
525525
)
526526
except OSError:
@@ -744,7 +744,7 @@ def get_source_of_current_name(self) -> str:
744744
msg = _("No source code found for %s") % (self.current_line,)
745745
raise SourceNotFound(msg)
746746

747-
def set_docstring(self):
747+
def set_docstring(self) -> None:
748748
self.docstring = None
749749
if not self.get_args():
750750
self.funcprops = None
@@ -1009,7 +1009,7 @@ def push(self, s, insert_into_history=True) -> bool:
10091009

10101010
return more
10111011

1012-
def insert_into_history(self, s):
1012+
def insert_into_history(self, s: str):
10131013
try:
10141014
self.rl_history.append_reload_and_write(
10151015
s, self.config.hist_file, getpreferredencoding()

bpython/test/test_history.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def test_reset(self):
8686
class TestHistoryFileAccess(unittest.TestCase):
8787
def setUp(self):
8888
self.tempdir = tempfile.TemporaryDirectory()
89-
self.filename = str(Path(self.tempdir.name) / "history_temp_file")
89+
self.filename = Path(self.tempdir.name) / "history_temp_file"
9090
self.encoding = getpreferredencoding()
9191

9292
with open(

0 commit comments

Comments
 (0)