From 6dc655898df34ad424dfc467a8b276fdf31bd791 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Wed, 5 Jun 2024 06:45:15 +0200 Subject: Merging upstream version 3.0.46. Signed-off-by: Daniel Baumann --- src/prompt_toolkit/filters/__init__.py | 1 + src/prompt_toolkit/filters/app.py | 1 + src/prompt_toolkit/filters/base.py | 14 ++++++++++---- src/prompt_toolkit/filters/cli.py | 1 + src/prompt_toolkit/filters/utils.py | 2 +- 5 files changed, 14 insertions(+), 5 deletions(-) (limited to 'src/prompt_toolkit/filters') diff --git a/src/prompt_toolkit/filters/__init__.py b/src/prompt_toolkit/filters/__init__.py index 277f428..556ed88 100644 --- a/src/prompt_toolkit/filters/__init__.py +++ b/src/prompt_toolkit/filters/__init__.py @@ -16,6 +16,7 @@ Filters can be chained using ``&`` and ``|`` operations, and inverted using the filter = has_focus('default') & ~ has_selection """ + from __future__ import annotations from .app import * diff --git a/src/prompt_toolkit/filters/app.py b/src/prompt_toolkit/filters/app.py index aacb228..b1b7c1b 100644 --- a/src/prompt_toolkit/filters/app.py +++ b/src/prompt_toolkit/filters/app.py @@ -1,6 +1,7 @@ """ Filters that accept a `Application` as argument. """ + from __future__ import annotations from typing import TYPE_CHECKING, cast diff --git a/src/prompt_toolkit/filters/base.py b/src/prompt_toolkit/filters/base.py index afce6dc..410749d 100644 --- a/src/prompt_toolkit/filters/base.py +++ b/src/prompt_toolkit/filters/base.py @@ -30,7 +30,7 @@ class Filter(metaclass=ABCMeta): """ Chaining of filters using the & operator. """ - assert isinstance(other, Filter), "Expecting filter, got %r" % other + assert isinstance(other, Filter), f"Expecting filter, got {other!r}" if isinstance(other, Always): return self @@ -48,7 +48,7 @@ class Filter(metaclass=ABCMeta): """ Chaining of filters using the | operator. """ - assert isinstance(other, Filter), "Expecting filter, got %r" % other + assert isinstance(other, Filter), f"Expecting filter, got {other!r}" if isinstance(other, Always): return other @@ -193,7 +193,7 @@ class _Invert(Filter): return not self.filter() def __repr__(self) -> str: - return "~%r" % self.filter + return f"~{self.filter!r}" class Always(Filter): @@ -207,6 +207,9 @@ class Always(Filter): def __or__(self, other: Filter) -> Filter: return self + def __and__(self, other: Filter) -> Filter: + return other + def __invert__(self) -> Never: return Never() @@ -222,6 +225,9 @@ class Never(Filter): def __and__(self, other: Filter) -> Filter: return self + def __or__(self, other: Filter) -> Filter: + return other + def __invert__(self) -> Always: return Always() @@ -248,7 +254,7 @@ class Condition(Filter): return self.func() def __repr__(self) -> str: - return "Condition(%r)" % self.func + return f"Condition({self.func!r})" # Often used as type annotation. diff --git a/src/prompt_toolkit/filters/cli.py b/src/prompt_toolkit/filters/cli.py index c95080a..902fbaa 100644 --- a/src/prompt_toolkit/filters/cli.py +++ b/src/prompt_toolkit/filters/cli.py @@ -2,6 +2,7 @@ For backwards-compatibility. keep this file. (Many people are going to have key bindings that rely on this file.) """ + from __future__ import annotations from .app import * diff --git a/src/prompt_toolkit/filters/utils.py b/src/prompt_toolkit/filters/utils.py index bac85ba..20e00ee 100644 --- a/src/prompt_toolkit/filters/utils.py +++ b/src/prompt_toolkit/filters/utils.py @@ -29,7 +29,7 @@ def to_filter(bool_or_filter: FilterOrBool) -> Filter: if isinstance(bool_or_filter, Filter): return bool_or_filter - raise TypeError("Expecting a bool or a Filter instance. Got %r" % bool_or_filter) + raise TypeError(f"Expecting a bool or a Filter instance. Got {bool_or_filter!r}") def is_true(value: FilterOrBool) -> bool: -- cgit v1.2.3