Skip to content

Boolean flags are always False #2897

@colmmurphyxyz

Description

@colmmurphyxyz

When upgrading from Click 8.1.8 to 8.2.0, I encountered a bug where boolean flags are not parsed correctly.

Reproduction

The below program can reproduce the error

from sys import exit
import click

@click.command(help="help")
@click.option("-v", "--version", type=click.BOOL, default=False, is_flag=True)
@click.option("-h", "--help", type=click.BOOL, default=False, is_flag=True)
@click.option("-n", "--name", type=click.STRING, default="John Doe")
def main(help, version, name):
    print(f"{help=}, {version=}, {name=}")
    if help:
        print("Help")
        exit(0)
    if version:
        print("v1.0.0")
        exit(0)
    print(f"Hello, {name}")

if __name__ == "__main__":
    main()
  • When running with click 8.1.8, all flags/options are parsed as expected
  • On 8.2.0, boolean flags are not parsed and remain at their default value
    • e.g. python main.py --help --name Robert will print help=False, version=False, name='Robert'

Environment:

  • OS: NixOS 24.11
  • Python version: 3.12.8
  • Click version: 8.2.0

I'm unsure if this is a regression in Click, or an issue on my end. Any help would be greatly appreciated. TIA!

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions