Skip to content
Myr

Deduplicate deprecated label translation (#3430)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Rowlando13 · committed by GitHub · parents 63daae2, 8438798 · Browse files · 2 files+30 added−32 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

2 files+30 added−32 removed

  • other:+30 added−32 removed

2 files+30 added−32 removed

modified:src/click/core.py+26 added-32 removed
91 unmodified lines
9293 raise RuntimeError(message)949596def _format_deprecated_label(deprecated: bool | str) -> str:97 """Return the parenthesized deprecation label shown in help text."""98 label = _("deprecated").upper()99 if isinstance(deprecated, str):100 return f"({label}: {deprecated})"101 return f"({label})"102103104def _format_deprecated_suffix(deprecated: bool | str) -> str:105 """Return the trailing reason for a ``DeprecationWarning`` message,106 prefixed with a space, or an empty string when no reason was given.107 """108 if isinstance(deprecated, str):109 return f" {deprecated}"110 return ""111112113def batch(iterable: cabc.Iterable[V], batch_size: int) -> list[tuple[V, ...]]:114 return list(zip(*repeat(iter(iterable), batch_size), strict=False))115116
1035 unmodified lines
1152 else:1153 text = ""11541155 if self.deprecated:1139 localised_deprectated = _("deprecated").upper()1140 deprecated_message = (1141 f"({localised_deprectated}: {self.deprecated})"1142 if isinstance(self.deprecated, str)1143 else f"({localised_deprectated})"1144 )1145 text = f"{_(text)} {deprecated_message}"1156 text = f"{_(text)} {_format_deprecated_label(self.deprecated)}"11571158 return text.strip()11591160 def format_help(self, ctx: Context, formatter: HelpFormatter) -> None:
21 unmodified lines
1182 else:1183 text = ""11841185 if self.deprecated:1175 localised_deprectated = _("deprecated").upper()1176 deprecated_message = (1177 f"({localised_deprectated}: {self.deprecated})"1178 if isinstance(self.deprecated, str)1179 else f"({localised_deprectated})"1180 )1181 text = f"{_(text)} {deprecated_message}"1186 text = f"{_(text)} {_format_deprecated_label(self.deprecated)}"11871188 if text:1189 formatter.write_paragraph()1190
98 unmodified lines
1289 """Given a context, this invokes the attached callback (if it exists)1290 in the right way.1291 """1292 if self.deprecated:1288 extra_message = (1289 f" {self.deprecated}" if isinstance(self.deprecated, str) else ""1290 )1293 message = _(1294 "DeprecationWarning: The command {name!r} is deprecated.{extra_message}"1293 ).format(name=self.name, extra_message=extra_message)1295 ).format(1296 name=self.name,1297 extra_message=_format_deprecated_suffix(self.deprecated),1298 )1299 echo(style(message, fg="red"), err=True)13001301 if self.callback is not None:1302 return ctx.invoke(self.callback, **ctx.params)
1293 unmodified lines
2596 self.deprecated2597 and value is not UNSET2598 and source < ParameterSource.DEFAULT_MAP2599 ):2595 extra_message = (2596 f" {self.deprecated}" if isinstance(self.deprecated, str) else ""2597 )2600 message = _(2601 "DeprecationWarning: The {param_type} {name!r} is deprecated."2602 "{extra_message}"2603 ).format(2604 param_type=self.param_type_name,2605 name=self.human_readable_name,2604 extra_message=extra_message,2606 extra_message=_format_deprecated_suffix(self.deprecated),2607 )2608 echo(style(message, fg="red"), err=True)26092610 # Process the value through the parameter's type.
171 unmodified lines
2782 else:2783 prompt_text = prompt27842785 if deprecated:2784 deprecated_message = (2785 f"(DEPRECATED: {deprecated})"2786 if isinstance(deprecated, str)2787 else "(DEPRECATED)"2788 )2789 help = (2790 f"{help} {deprecated_message}"2791 if help is not None2792 else deprecated_message2793 )2786 label = _format_deprecated_label(deprecated)2787 help = f"{help} {label}" if help is not None else label27882789 self.prompt = prompt_text2790 self.confirmation_prompt = confirmation_prompt2791 self.prompt_required = prompt_required
709 unmodified lines
modified:CHANGES.rst+4 added
55 unmodified lines
56- Show custom error messages from types when :func:`prompt` with57 ``hide_input=True`` fails validation, instead of always showing a58 generic message. Built-in type messages mask the input value.59 :issue:`2809` :pr:`3256`60- Fix missing space between option help text and the ``(DEPRECATED)``61 label, and localize the option label so it matches the command label.62 The label and the ``DeprecationWarning`` reason suffix are now produced63 by shared helpers. :pr:`3423`64- Document short option stacking (``-abc`` is parsed as ``-a -b -c``) and65 clarify that multi-character short option names are not supported.66 :issue:`2779` :pr:`3431`67
1367 unmodified lines