Skip to content

Commit 8fd6d50

Browse files
committed
switch _initialize_history() from os.path to pathlib
1 parent 5fe14a2 commit 8fd6d50

File tree

1 file changed

+7
-6
lines changed

1 file changed

+7
-6
lines changed

cmd2/cmd2.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
import glob
3535
import inspect
3636
import os
37+
import pathlib
3738
import pickle
3839
import re
3940
import sys
@@ -3465,29 +3466,29 @@ def _initialize_history(self, hist_file):
34653466
self.persistent_history_file = hist_file
34663467
return
34673468

3468-
hist_file = os.path.expanduser(hist_file)
3469+
histpath = pathlib.Path(hist_file).expanduser().resolve()
34693470

34703471
# first we try and unpickle the history file
34713472
history = History()
34723473
# on Windows, trying to open a directory throws a permission
34733474
# error, not a `IsADirectoryError`. So we'll check it ourselves.
3474-
if os.path.isdir(hist_file):
3475+
if histpath.is_dir():
34753476
msg = "persistent history file '{}' is a directory"
3476-
self.perror(msg.format(hist_file))
3477+
self.perror(msg.format(histpath))
34773478
return
34783479

34793480
try:
3480-
with open(hist_file, 'rb') as fobj:
3481+
with open(str(histpath), 'rb') as fobj:
34813482
history = pickle.load(fobj)
34823483
except (FileNotFoundError, KeyError, EOFError):
34833484
pass
34843485
except OSError as ex:
34853486
msg = "can not read persistent history file '{}': {}"
3486-
self.perror(msg.format(hist_file, ex), traceback_war=False)
3487+
self.perror(msg.format(histpath, ex), traceback_war=False)
34873488
return
34883489

34893490
self.history = history
3490-
self.persistent_history_file = hist_file
3491+
self.persistent_history_file = str(histpath)
34913492

34923493
# populate readline history
34933494
if rl_type != RlType.NONE:

0 commit comments

Comments
 (0)