Skip to content

Commit 74d7795

Browse files
committed
Restore more f-strings that do not need localisation
Some f-strings changed to the format method in earlier commits do not need localisation. This commit restores them to reduce the amount of changes.
1 parent 4768c98 commit 74d7795

File tree

5 files changed

+33
-61
lines changed

5 files changed

+33
-61
lines changed

src/click/core.py

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,19 +84,15 @@ def _check_nested_chain(
8484
return
8585

8686
if register:
87-
message = (
87+
message = _(
8888
"It is not possible to add the group {cmd_name!r} to another"
89-
" group {base_cmd_name!r} that is in chain mode.".format(
90-
cmd_name=cmd_name, base_cmd_name=base_command.name
91-
) # noqa: UP032
92-
)
89+
" group {base_cmd_name!r} that is in chain mode."
90+
).format(cmd_name=cmd_name, base_cmd_name=base_command.name) # noqa: UP032
9391
else:
94-
message = (
92+
message = _(
9593
"Found the group {cmd_name!r} as subcommand to another group "
96-
" {base_cmd_name!r} that is in chain mode. This is not supported.".format(
97-
cmd_name=cmd_name, base_cmd_name=base_command.name
98-
) # noqa: UP032
99-
)
94+
" {base_cmd_name!r} that is in chain mode. This is not supported."
95+
).format(cmd_name=cmd_name, base_cmd_name=base_command.name) # noqa: UP032
10096

10197
raise RuntimeError(message)
10298

@@ -2137,10 +2133,10 @@ def __init__(
21372133
if __debug__:
21382134
if self.type.is_composite and nargs != self.type.arity:
21392135
raise ValueError(
2140-
"'nargs' must be {arity} (or None) for"
2141-
" type {type!r}, but it was {nargs}.".format(
2142-
arity=self.type.arity, type=self.type, nargs=nargs
2143-
)
2136+
_(
2137+
"'nargs' must be {arity} (or None) for"
2138+
" type {type!r}, but it was {nargs}."
2139+
).format(arity=self.type.arity, type=self.type, nargs=nargs)
21442140
)
21452141

21462142
# Skip no default or callable default.

src/click/decorators.py

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ def new_func(*args: P.args, **kwargs: P.kwargs) -> R:
9393

9494
if obj is None:
9595
raise RuntimeError(
96-
"Managed to invoke callback without a context"
97-
" object of type {type!r}"
98-
" existing.".format(type=object_type.__name__) # noqa: UP032
96+
_(
97+
"Managed to invoke callback without a context"
98+
" object of type {type!r}"
99+
" existing."
100+
).format(type=object_type.__name__) # noqa: UP032
99101
) # noqa: UP032
100102

101103
return ctx.invoke(f, obj, *args, **kwargs)
@@ -129,14 +131,14 @@ def new_func(*args: P.args, **kwargs: P.kwargs) -> R:
129131
return update_wrapper(new_func, f)
130132

131133
if doc_description is None:
132-
doc_description = "the {key!r} key from :attr:`click.Context.meta`".format(
134+
doc_description = _("the {key!r} key from :attr:`click.Context.meta`").format(
133135
key=key
134136
) # noqa: UP032
135137

136-
decorator.__doc__ = (
138+
decorator.__doc__ = _(
137139
"Decorator that passes {description} as the first argument"
138-
" to the decorated function.".format(description=doc_description) # noqa: UP032
139-
)
140+
" to the decorated function."
141+
).format(description=doc_description) # noqa: UP032
140142
return decorator
141143

142144

@@ -508,13 +510,15 @@ def callback(ctx: Context, param: Parameter, value: bool) -> None:
508510
version = importlib.metadata.version(package_name)
509511
except importlib.metadata.PackageNotFoundError:
510512
raise RuntimeError(
511-
"{name!r} is not installed. Try passing"
512-
" 'package_name' instead.".format(name=package_name) # noqa: UP032
513+
_(
514+
"{name!r} is not installed. Try passing"
515+
" 'package_name' instead."
516+
).format(name=package_name) # noqa: UP032
513517
) from None
514518

515519
if version is None:
516520
raise RuntimeError(
517-
"Could not determine the version for {name!r} automatically.".format(
521+
_("Could not determine the version for {name!r} automatically.").format(
518522
name=package_name
519523
) # noqa: UP032
520524
)

src/click/formatting.py

Lines changed: 4 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -155,9 +155,7 @@ def write_usage(self, prog: str, args: str = "", prefix: str | None = None) -> N
155155
if prefix is None:
156156
prefix = "{usage} ".format(usage=_("Usage:"))
157157

158-
usage_prefix = "{prefix:>{indent}}{prog} ".format(
159-
prefix=prefix, indent=self.current_indent, prog=prog
160-
)
158+
usage_prefix = f"{prefix:>{self.current_indent}}{prog} "
161159
text_width = self.width - self.current_indent
162160

163161
if text_width >= (term_len(usage_prefix) + 20):
@@ -186,11 +184,7 @@ def write_usage(self, prog: str, args: str = "", prefix: str | None = None) -> N
186184

187185
def write_heading(self, heading: str) -> None:
188186
"""Writes a heading into the buffer."""
189-
self.write(
190-
"{prefix:>{indent}}{message}:\n".format(
191-
prefix="", indent=self.current_indent, message=heading
192-
)
193-
)
187+
self.write(f"{'':>{self.current_indent}}{heading}:\n")
194188

195189
def write_paragraph(self) -> None:
196190
"""Writes a paragraph into the buffer."""
@@ -235,11 +229,7 @@ def write_dl(
235229
first_col = min(widths[0], col_max) + col_spacing
236230

237231
for first, second in iter_rows(rows, len(widths)):
238-
self.write(
239-
"{prefix:>{indent}}{message}".format(
240-
prefix="", indent=self.current_indent, message=first
241-
)
242-
)
232+
self.write(f"{'':>{self.current_indent}}{first}")
243233
if not second:
244234
self.write("\n")
245235
continue
@@ -257,13 +247,7 @@ def write_dl(
257247
self.write(f"{lines[0]}\n")
258248

259249
for line in lines[1:]:
260-
self.write(
261-
"{prefix:>{indent}}{message}\n".format(
262-
prefix="",
263-
indent=first_col + self.current_indent,
264-
message=line,
265-
)
266-
)
250+
self.write(f"{'':>{first_col + self.current_indent}}{line}\n")
267251
else:
268252
self.write("\n")
269253

src/click/shell_completion.py

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,3 @@
1-
# Ask Ruff to accept the format method on strings, and not let pyupgrade
2-
# always force f-strings. The latter are unfortunately not supported yet
3-
# by Babel, a localisation library.
4-
#
5-
# Note: Using `# noqa: UP032` on lines has not worked, so a file
6-
# setting.
7-
# ruff: noqa: UP032
8-
91
from __future__ import annotations
102

113
import collections.abc as cabc
@@ -381,9 +373,7 @@ def get_completion_args(self) -> tuple[list[str], str]:
381373
return args, incomplete
382374

383375
def format_completion(self, item: CompletionItem) -> str:
384-
return "{type}\n{value}\n{help}".format(
385-
type=item.type, value=item.value, help=item.help if item.help else "_"
386-
)
376+
return f"{item.type}\n{item.value}\n{item.help if item.help else '_'}"
387377

388378

389379
class FishComplete(ShellComplete):
@@ -406,9 +396,7 @@ def get_completion_args(self) -> tuple[list[str], str]:
406396

407397
def format_completion(self, item: CompletionItem) -> str:
408398
if item.help:
409-
return "{type},{value}\t{help}".format(
410-
type=item.type, value=item.value, help=item.help
411-
) # noqa: UP032
399+
return f"{item.type},{item.value}\t{item.help}"
412400

413401
return f"{item.type},{item.value}"
414402

src/click/types.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,10 +326,10 @@ def get_metavar(self, param: Parameter, ctx: Context) -> str | None:
326326

327327
# Use curly braces to indicate a required argument.
328328
if param.required and param.param_type_name == "argument":
329-
return "{{{choices}}}".format(choices=choices_str) # noqa: UP032
329+
return f"{{{choices_str}}}"
330330

331331
# Use square braces to indicate an option or optional argument.
332-
return "[{choices}]".format(choices=choices_str) # noqa: UP032
332+
return f"[{choices_str}]"
333333

334334
def get_missing_message(self, param: Parameter, ctx: Context | None) -> str:
335335
"""
@@ -442,7 +442,7 @@ def to_info_dict(self) -> dict[str, t.Any]:
442442
return info_dict
443443

444444
def get_metavar(self, param: Parameter, ctx: Context) -> str | None:
445-
return "[{formats}]".format(formats="|".join(self.formats)) # noqa: UP032
445+
return f"[{'|'.join(self.formats)}]"
446446

447447
def _try_to_convert_date(self, value: t.Any, format: str) -> datetime | None:
448448
try:

0 commit comments

Comments
 (0)