Skip to content

default=True on feature flags is order-sensitiveΒ #3071

@jwodder

Description

@jwodder

The following code:

import click


@click.command()
@click.option("--red", "color", flag_value="red")
@click.option("--green", "color", flag_value="green", default=True)
@click.option("--blue", "color", flag_value="blue")
def main(color: str) -> None:
    print(repr(color))


if __name__ == "__main__":
    main()

when run with no arguments using click 8.2.1 outputs 'green', which is what I expect. If click 8.3.0 is used instead, then it outputs None β€” but if the --green option is moved above the --red option in the script, click 8.3.0 will output 'green'.

I believe that the script should output 'green' regardless of the declaration order of the options.

Environment:

  • Python version: 3.13.7
  • Click version: 8.2.1 and 8.3.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions