From 341a079a4798ffe73708578a518620fa435fb2a7 Mon Sep 17 00:00:00 2001 From: deathaxe Date: Sat, 7 Feb 2026 12:08:00 +0100 Subject: [PATCH] Replace str.format() by f-strings --- sublime_lib/activity_indicator.py | 2 +- sublime_lib/encodings.py | 4 ++-- sublime_lib/flags.py | 8 ++++---- sublime_lib/panel.py | 2 +- sublime_lib/resource_path.py | 12 +++++------- 5 files changed, 13 insertions(+), 15 deletions(-) diff --git a/sublime_lib/activity_indicator.py b/sublime_lib/activity_indicator.py index 1c7d569..a52553a 100644 --- a/sublime_lib/activity_indicator.py +++ b/sublime_lib/activity_indicator.py @@ -38,7 +38,7 @@ class ViewTarget(StatusTarget): def __init__(self, view: sublime.View, key: str | None = None) -> None: self.view: sublime.View = view if key is None: - self.key: str = '_{!s}'.format(uuid4()) + self.key: str = f"_{uuid4()!s}" else: self.key = key diff --git a/sublime_lib/encodings.py b/sublime_lib/encodings.py index 93c97a9..2350fdc 100644 --- a/sublime_lib/encodings.py +++ b/sublime_lib/encodings.py @@ -21,7 +21,7 @@ def from_sublime(name: str) -> str: try: return SUBLIME_TO_STANDARD[name] except KeyError: - raise ValueError("Unknown Sublime encoding {!r}.".format(name)) from None + raise ValueError(f"Unknown Sublime encoding {name!r}.") from None def to_sublime(name: str) -> str: @@ -40,7 +40,7 @@ def to_sublime(name: str) -> str: try: return STANDARD_TO_SUBLIME[lookup(name).name] except LookupError: - raise ValueError("Unknown Python encoding {!r}.".format(name)) from None + raise ValueError(f"Unknown Python encoding {name!r}.") from None SUBLIME_TO_STANDARD = { diff --git a/sublime_lib/flags.py b/sublime_lib/flags.py index cd4e1b6..a0ad53f 100644 --- a/sublime_lib/flags.py +++ b/sublime_lib/flags.py @@ -53,10 +53,10 @@ def autodoc(prefix: str | None = None) -> Callable[[EnumMeta], EnumMeta]: def decorator(enum: EnumMeta) -> EnumMeta: enum.__doc__ = (getdoc(enum) or '') + '\n\n' + '\n'.join([ - cleandoc(""" + cleandoc(f""" .. py:attribute:: {name} - :annotation: = sublime.{pre}{name} - """).format(name=name, pre=prefix_str) for name in enum.__members__ + :annotation: = sublime.{prefix_str}{name} + """) for name in enum.__members__ ]) return enum @@ -244,7 +244,7 @@ class HoverLocation(IntEnum): def regex_match(value: str, operand: str) -> bool: - expr = r'(?:{})\Z'.format(operand) + expr = rf"(?:{operand})\Z" return re.match(expr, value) is not None diff --git a/sublime_lib/panel.py b/sublime_lib/panel.py index 9d42675..a9650a2 100644 --- a/sublime_lib/panel.py +++ b/sublime_lib/panel.py @@ -34,7 +34,7 @@ def __init__(self, window: sublime.Window, panel_name: str): def _checkExists(self) -> None: if not self.exists(): - raise ValueError("Panel {} does not exist.".format(self.panel_name)) + raise ValueError(f"Panel {self.panel_name} does not exist.") @define_guard def guard_exists(self) -> None: diff --git a/sublime_lib/resource_path.py b/sublime_lib/resource_path.py index b16b06e..3109be5 100644 --- a/sublime_lib/resource_path.py +++ b/sublime_lib/resource_path.py @@ -204,9 +204,7 @@ def from_file_path(cls, file_path: Path | str) -> ResourcePath: if path: return path else: - raise ValueError( - "Path {!r} does not correspond to any resource path.".format(file_path) - ) + raise ValueError(f"Path {file_path!r} does not correspond to any resource path.") def __init__(self, *pathsegments: object): """ @@ -234,7 +232,7 @@ def __hash__(self) -> int: return hash(self.parts) def __repr__(self) -> str: - return "{}({!r})".format(self.__class__.__name__, str(self)) + return f"{self.__class__.__name__}({self!s})" def __str__(self) -> str: return '/'.join(self.parts) @@ -365,7 +363,7 @@ def relative_to(self, *other: object) -> tuple[str, ...]: if other_path.parts == self._parts[:other_len]: return self._parts[other_len:] else: - raise ValueError("{!s} does not start with {!s}".format(self, other_path)) + raise ValueError(f"{self!s} does not start with {other_path!s}") def with_name(self, name: str) -> ResourcePath: """ @@ -422,7 +420,7 @@ def remove_suffix( if new_name is not None: return self.with_name(new_name) elif must_remove: - raise ValueError('Cannot remove suffix {!r} from {!r}.'.format(suffix, self)) + raise ValueError(f"Cannot remove suffix {suffix!r} from {self!r}.") else: return self @@ -455,7 +453,7 @@ def file_path(self) -> Path: except ValueError: continue - raise ValueError("Can't find a filesystem path for {!r}.".format(self.root)) from None + raise ValueError(f"Can't find a filesystem path for {self.root!r}.") from None def exists(self) -> bool: """