fix: show default values for single boolean flags with default=False#1490
fix: show default values for single boolean flags with default=False#1490timonrieger wants to merge 1 commit intofastapi:masterfrom
Conversation
Previously, single boolean flags (without secondary --no-* options) with default=False would not display their default value in help text, even when show_default=True was set. This made it inconsistent with dual-flag options and other parameter types. Removed the special case in _get_default_string() that hid defaults for single boolean flags with falsy default values. Now all boolean flags consistently show their default values in help text. Example: Before: --dry-run Simulate uploads without actually uploading After: --dry-run Simulate uploads without actually uploading [default: False] Fixes inconsistency where show_default=True had no effect for single boolean flags with default=False.
|
alternatively we could do elif (
isinstance(obj, TyperOption)
and obj.is_bool_flag
and not obj.secondary_opts
and not default_value
+ and not (obj.show_default or ctx.show_default)
):
default_string = "" |
|
added some tests as pr to this pr: timonrieger#1 |
Colleagues of mine and I discussed the two options you suggested and we like this option here better. |
sounds good. your tests cover the alternative implementation, right? I’ll wait for the maintainers response for the way to go, before merging it 😄 |
the tests should cover both implementations, as the desired functionality is tested, but the branch is forked from your first / current implementation |
Previously, single boolean flags (without secondary --no-* options) with
default=False would not display their default value in help text, even
when show_default=True was set. This made it inconsistent with dual-flag
options and other parameter types.
Removed the special case in _get_default_string() that hid defaults for
single boolean flags with falsy default values. Now all boolean flags
consistently show their default values in help text.
Before: --dry-run Simulate uploads without actually uploading
After: --dry-run Simulate uploads without actually uploading [default: False]
Fixes inconsistency where show_default=True had no effect for single
boolean flags with default=False.