diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 04:45:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-06-05 04:45:14 +0000 |
commit | 5b43aaac61ac94abe722bc98ae58468618f2f512 (patch) | |
tree | 3d58c89faa23d194f83abb24ae1fd05067538fff /src/prompt_toolkit/history.py | |
parent | Adding upstream version 3.0.43. (diff) | |
download | prompt-toolkit-5b43aaac61ac94abe722bc98ae58468618f2f512.tar.xz prompt-toolkit-5b43aaac61ac94abe722bc98ae58468618f2f512.zip |
Adding upstream version 3.0.46.upstream/3.0.46
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/prompt_toolkit/history.py')
-rw-r--r-- | src/prompt_toolkit/history.py | 12 |
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") |