Skip to content

"default" behaviour in Click 8.3.x changes with enable/disable boolean flag pair #3403

@freakboy3742

Description

@freakboy3742

In click 8.2.1, defining a boolean option with both a "enable" and "disable" flag option works with the following logic:

import click

@click.command("foo")
@click.option("--without-xyz", "enable_xyz", flag_value=False)
@click.option("--with-xyz", "enable_xyz", flag_value=True, default=True)
def foo(enable_xyz):
    print(f"enable_xyz = {enable_xyz}")

foo()

With this code, using click 8.2.1:

  • python foo.py --with-xyz returns True
  • python foo.py --without-xyz returns False
  • python foo.py --with-xyz --without-xyz returns False
  • python foo.py --without-xyz --with-xyz returns True
  • python foo.py returns False

In click 8.3.0, the output is the same for every case except the "default" case - python foo.py returns True.

This is an extension of #3111; this pattern is used in MkDocs (as of MkDocs 1.6.1) (see mkdocs/mkdocs#4032).

However, the fix for #3111 (#3239) doesn't fix this edge case.

The Properdocs fork of MkDocs has worked around the issue.

Environment:

  • Python version: 3.12, 3.13, 3.14
  • Click version: 8.3.0, 8.3.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugf:parametersfeature: input parameter types

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions