Skip to content
Myr

Fix printing of default option value to handle empty strings (#2724)

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

authored by David Lord · committed by GitHub · parents c021f05, 61f8101 · Browse files · 3 files+12 added−0 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+12 added−0 removed

  • tests:+8 added−0 removed
  • other:+4 added−0 removed

3 files+12 added−0 removed

modified:src/click/core.py+2 added
2802 unmodified lines
2803 (self.opts if self.default else self.secondary_opts)[0]2804 )[1]2805 elif self.is_bool_flag and not self.secondary_opts and not default_value:2806 default_string = ""2807 elif default_value == "":2808 default_string = '""'2809 else:2810 default_string = str(default_value)28112812 if default_string:
220 unmodified lines
modified:tests/test_options.py+8 added
784 unmodified lines
785 message = opt.get_help_record(ctx)[1]786 assert "[default: (unlimited)]" in message787788789def test_show_default_with_empty_string(runner):790 """When show_default is True and default is set to an empty string."""791 opt = click.Option(["--limit"], default="", show_default=True)792 ctx = click.Context(click.Command("cli"))793 message = opt.get_help_record(ctx)[1]794 assert '[default: ""]' in message795796797def test_do_not_show_no_default(runner):798 """When show_default is True and no default is set do not show None."""799 opt = click.Option(["--limit"], show_default=True)800 ctx = click.Context(click.Command("cli"))
128 unmodified lines
modified:CHANGES.rst+2 added
6 unmodified lines
78- Fix an issue with type hints for ``click.open_file()``. :issue:`2717`9- Fix issue where error message for invalid ``click.Path`` displays on10 multiple lines. :issue:`2697`11- Fixed issue that prevented a default value of ``""`` from being displayed in12 the help for an option. :issue:`2500`131415Version 8.1.716-------------
1102 unmodified lines