From 5b43aaac61ac94abe722bc98ae58468618f2f512 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 5 Jun 2024 06:45:14 +0200 Subject: Adding upstream version 3.0.46. Signed-off-by: Daniel Baumann --- src/prompt_toolkit/history.py | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) (limited to 'src/prompt_toolkit/history.py') 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") -- cgit v1.2.3