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
In click 8.2.1, defining a boolean option with both a "enable" and "disable" flag option works with the following logic:
With this code, using click 8.2.1:
python foo.py --with-xyzreturns Truepython foo.py --without-xyzreturns Falsepython foo.py --with-xyz --without-xyzreturns Falsepython foo.py --without-xyz --with-xyzreturns Truepython foo.pyreturns FalseIn click 8.3.0, the output is the same for every case except the "default" case -
python foo.pyreturns 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: