Skip to content

Conversation

@timonrieger
Copy link

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.

    dry_run: bool = typer.Option(
        False,
        "--dry-run",
        help="Simulate uploads without actually uploading",
    ),

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.

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.
@timonrieger
Copy link
Author

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 = ""

@svlandeg svlandeg added the bug Something isn't working label Jan 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants