Skip to content
Myr

Fix deprecated label formatting (#3509)

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

authored by Rowlando13 · committed by GitHub · parents 648d7c4, 82f377c · Browse files · 4 files+35 added−2 removed
This commit

State

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

Diff stats

4 files+35 added−2 removed

  • tests:+30 added−0 removed
  • other:+5 added−2 removed

4 files+35 added−2 removed

modified:src/click/core.py+3 added-2 removed
1187 unmodified lines
1188 else:1189 text = ""11901191 if self.deprecated:1192 text = f"{_(text)} {_format_deprecated_label(self.deprecated)}"1192 label = _format_deprecated_label(self.deprecated)1193 text = f"{_(text)} {label}" if text else label11941195 if text:1196 formatter.write_paragraph()1197
1628 unmodified lines
2826 prompt_text = prompt28272828 if deprecated:2829 label = _format_deprecated_label(deprecated)2829 help = f"{help} {label}" if help is not None else label2830 help = f"{help} {label}" if help else label28312832 self.prompt = prompt_text2833 self.confirmation_prompt = confirmation_prompt2834 self.prompt_required = prompt_required
709 unmodified lines
modified:tests/test_commands.py+16 added
490 unmodified lines
491 assert deprecated in result.output492493494@pytest.mark.parametrize("deprecated", [True, "USE OTHER COMMAND INSTEAD"])495@pytest.mark.parametrize("doc", ["", None])496def test_deprecated_empty_help_no_leading_space(runner, doc, deprecated):497 """A command with empty or missing help text must render the deprecation498 label at the normal indentation, without a stray leading space.499 """500501 @click.command(deprecated=deprecated, help=doc)502 def cli():503 pass504505 out = runner.invoke(cli, ["--help"]).output506 assert "\n (DEPRECATED" in out507 assert "\n (DEPRECATED" not in out508509510@pytest.mark.parametrize("deprecated", [True, "USE OTHER COMMAND INSTEAD"])511def test_deprecated_in_invocation(runner, deprecated):512 @click.command(deprecated=deprecated)513 def deprecated_cmd():514 pass
109 unmodified lines
modified:tests/test_options.py+14 added
56 unmodified lines
57 if isinstance(deprecated, str):58 assert deprecated in result.output596061@pytest.mark.parametrize(62 ("deprecated", "expected"),63 [(True, "(DEPRECATED)"), ("USE B INSTEAD", "(DEPRECATED: USE B INSTEAD)")],64)65@pytest.mark.parametrize("help_text", ["", None])66def test_deprecated_empty_help_no_leading_space(help_text, deprecated, expected):67 """An option with empty or missing help text must not gain a stray leading68 space before the deprecation label.69 """70 opt = click.Option(["--foo"], help=help_text, deprecated=deprecated)71 ctx = click.Context(click.Command("cli"))72 assert opt.get_help_record(ctx)[1] == expected737475@pytest.mark.parametrize("deprecated", [True, "USE B INSTEAD"])76def test_deprecated_warning(runner, deprecated):77 @click.command()78 @click.option(
3439 unmodified lines
modified:CHANGES.rst+2 added
7 unmodified lines
8- Fix Fish shell completion broken in ``8.4.0`` by :pr:`3126`. Newlines and9 tabs in option help text are now escaped, keeping the original completion10 format while still supporting multi-line help. :issue:`3502`11 :issue:`3043` :pr:`3504` :pr:`3508`12- Deprecated commands and options with empty or missing help text no longer13 render a stray leading space before the ``(DEPRECATED)`` label. :pr:`3509`141516Version 8.4.117-------------
1476 unmodified lines