Skip to content

Commit 1508802

Browse files
authored
Replace str.format() by f-strings (#194)
1 parent 3c5a363 commit 1508802

5 files changed

Lines changed: 13 additions & 15 deletions

File tree

sublime_lib/activity_indicator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ class ViewTarget(StatusTarget):
3838
def __init__(self, view: sublime.View, key: str | None = None) -> None:
3939
self.view: sublime.View = view
4040
if key is None:
41-
self.key: str = '_{!s}'.format(uuid4())
41+
self.key: str = f"_{uuid4()!s}"
4242
else:
4343
self.key = key
4444

sublime_lib/encodings.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ def from_sublime(name: str) -> str:
2121
try:
2222
return SUBLIME_TO_STANDARD[name]
2323
except KeyError:
24-
raise ValueError("Unknown Sublime encoding {!r}.".format(name)) from None
24+
raise ValueError(f"Unknown Sublime encoding {name!r}.") from None
2525

2626

2727
def to_sublime(name: str) -> str:
@@ -40,7 +40,7 @@ def to_sublime(name: str) -> str:
4040
try:
4141
return STANDARD_TO_SUBLIME[lookup(name).name]
4242
except LookupError:
43-
raise ValueError("Unknown Python encoding {!r}.".format(name)) from None
43+
raise ValueError(f"Unknown Python encoding {name!r}.") from None
4444

4545

4646
SUBLIME_TO_STANDARD = {

sublime_lib/flags.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -53,10 +53,10 @@ def autodoc(prefix: str | None = None) -> Callable[[EnumMeta], EnumMeta]:
5353

5454
def decorator(enum: EnumMeta) -> EnumMeta:
5555
enum.__doc__ = (getdoc(enum) or '') + '\n\n' + '\n'.join([
56-
cleandoc("""
56+
cleandoc(f"""
5757
.. py:attribute:: {name}
58-
:annotation: = sublime.{pre}{name}
59-
""").format(name=name, pre=prefix_str) for name in enum.__members__
58+
:annotation: = sublime.{prefix_str}{name}
59+
""") for name in enum.__members__
6060
])
6161

6262
return enum
@@ -244,7 +244,7 @@ class HoverLocation(IntEnum):
244244

245245

246246
def regex_match(value: str, operand: str) -> bool:
247-
expr = r'(?:{})\Z'.format(operand)
247+
expr = rf"(?:{operand})\Z"
248248
return re.match(expr, value) is not None
249249

250250

sublime_lib/panel.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def __init__(self, window: sublime.Window, panel_name: str):
3434

3535
def _checkExists(self) -> None:
3636
if not self.exists():
37-
raise ValueError("Panel {} does not exist.".format(self.panel_name))
37+
raise ValueError(f"Panel {self.panel_name} does not exist.")
3838

3939
@define_guard
4040
def guard_exists(self) -> None:

sublime_lib/resource_path.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -204,9 +204,7 @@ def from_file_path(cls, file_path: Path | str) -> ResourcePath:
204204
if path:
205205
return path
206206
else:
207-
raise ValueError(
208-
"Path {!r} does not correspond to any resource path.".format(file_path)
209-
)
207+
raise ValueError(f"Path {file_path!r} does not correspond to any resource path.")
210208

211209
def __init__(self, *pathsegments: object):
212210
"""
@@ -234,7 +232,7 @@ def __hash__(self) -> int:
234232
return hash(self.parts)
235233

236234
def __repr__(self) -> str:
237-
return "{}({!r})".format(self.__class__.__name__, str(self))
235+
return f"{self.__class__.__name__}({self!s})"
238236

239237
def __str__(self) -> str:
240238
return '/'.join(self.parts)
@@ -365,7 +363,7 @@ def relative_to(self, *other: object) -> tuple[str, ...]:
365363
if other_path.parts == self._parts[:other_len]:
366364
return self._parts[other_len:]
367365
else:
368-
raise ValueError("{!s} does not start with {!s}".format(self, other_path))
366+
raise ValueError(f"{self!s} does not start with {other_path!s}")
369367

370368
def with_name(self, name: str) -> ResourcePath:
371369
"""
@@ -422,7 +420,7 @@ def remove_suffix(
422420
if new_name is not None:
423421
return self.with_name(new_name)
424422
elif must_remove:
425-
raise ValueError('Cannot remove suffix {!r} from {!r}.'.format(suffix, self))
423+
raise ValueError(f"Cannot remove suffix {suffix!r} from {self!r}.")
426424
else:
427425
return self
428426

@@ -455,7 +453,7 @@ def file_path(self) -> Path:
455453
except ValueError:
456454
continue
457455

458-
raise ValueError("Can't find a filesystem path for {!r}.".format(self.root)) from None
456+
raise ValueError(f"Can't find a filesystem path for {self.root!r}.") from None
459457

460458
def exists(self) -> bool:
461459
"""

0 commit comments

Comments
 (0)