Skip to content
Myr

show_default string is shown if default is None

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

authored by Benjamin Akhras · committed by David Lord · parent 7dd9b12 · Browse files · 3 files+15 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

3 files+15 added−2 removed

  • tests:+8 added−0 removed
  • other:+7 added−2 removed

3 files+15 added−2 removed

modified:src/click/core.py+5 added-2 removed
2403 unmodified lines
2404 )2405 extra.append(f"env var: {var_str}")24062407 default_value = self.get_default(ctx, call=False)2408 show_default_is_str = isinstance(self.show_default, str)24092409 if default_value is not None and (self.show_default or ctx.show_default):2410 if isinstance(self.show_default, str):2410 if show_default_is_str or (2411 default_value is not None and (self.show_default or ctx.show_default)2412 ):2413 if show_default_is_str:2414 default_string = f"({self.show_default})"2415 elif isinstance(default_value, (list, tuple)):2416 default_string = ", ".join(str(d) for d in default_value)2417 elif callable(default_value):
186 unmodified lines
modified:tests/test_options.py+8 added
658 unmodified lines
659 message = opt.get_help_record(ctx)[1]660 assert "[default: False]" in message661662663def test_show_default_string(runner):664 """When show_default is a string show that value as default."""665 opt = click.Option(["--limit"], show_default="unlimited")666 ctx = click.Context(click.Command("cli"))667 message = opt.get_help_record(ctx)[1]668 assert "[default: (unlimited)]" in message669670671@pytest.mark.parametrize(672 ("args", "expect"),673 [674 (None, (None, None, ())),
25 unmodified lines
modified:CHANGES.rst+2 added
155 unmodified lines
156- Respect ``case_sensitive=False`` when doing shell completion for157 ``Choice`` :issue:`1692`158- Use ``mkstemp()`` instead of ``mktemp()`` in pager implementation.159 :issue:`1752`160- If ``Option.show_default`` is a string, it is displayed even if161 ``default`` is ``None``. :issue:`1732`162163164Version 7.1.2165-------------
635 unmodified lines