summaryrefslogtreecommitdiffstats
path: root/src/prompt_toolkit/history.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/prompt_toolkit/history.py')
-rw-r--r--src/prompt_toolkit/history.py12
1 files changed, 8 insertions, 4 deletions
diff --git a/src/prompt_toolkit/history.py b/src/prompt_toolkit/history.py
index 553918e..2d497a0 100644
--- a/src/prompt_toolkit/history.py
+++ b/src/prompt_toolkit/history.py
@@ -7,6 +7,7 @@ NOTE: There is no `DynamicHistory`:
loading can be done asynchronously and making the history swappable would
probably break this.
"""
+
from __future__ import annotations
import datetime
@@ -14,7 +15,7 @@ import os
import threading
from abc import ABCMeta, abstractmethod
from asyncio import get_running_loop
-from typing import AsyncGenerator, Iterable, Sequence
+from typing import AsyncGenerator, Iterable, Sequence, Union
__all__ = [
"History",
@@ -254,12 +255,15 @@ class DummyHistory(History):
pass
+_StrOrBytesPath = Union[str, bytes, "os.PathLike[str]", "os.PathLike[bytes]"]
+
+
class FileHistory(History):
"""
:class:`.History` class that stores all strings in a file.
"""
- def __init__(self, filename: str) -> None:
+ def __init__(self, filename: _StrOrBytesPath) -> None:
self.filename = filename
super().__init__()
@@ -297,6 +301,6 @@ class FileHistory(History):
def write(t: str) -> None:
f.write(t.encode("utf-8"))
- write("\n# %s\n" % datetime.datetime.now())
+ write(f"\n# {datetime.datetime.now()}\n")
for line in string.split("\n"):
- write("+%s\n" % line)
+ write(f"+{line}\n")