We found a breaking change in the latest version of click! ❗
The example for optional value for an option, using flag_value is not correctly working anymore.
Example
import click
@click.command()
@click.option("--number", is_flag=False, flag_value=1, default=0)
def hello(number):
click.echo(f"Hello, number is: {number}!")
hello()
With this python script, then you can try 3 different options:
Without option: python example.py outputs Hello, number is: 0!
With option (no value): python example.py --number outputs Error: Option '--number' requires an argument. ❌
With option an value: python example.py --number 3 outputs Hello, number is: 3!
Expected behaviour
With option (no value): python example.py --number outputs Hello, number is: 1! ✅
The expected behaviour is, as described in the click documentation (see Optional Value) that the option has a flag_value which is set to 1.
Or that is how I understand that it should also work.
PD: it works the same way with string and not numbers (so the exact example set in the documentation, I put numbers because it is also my use case.
Environment:
- Python version: 3.12.3
- Click version: 8.3.1
We found a breaking change in the latest version of click! ❗
The example for optional value for an option, using
flag_valueis not correctly working anymore.Example
With this python script, then you can try 3 different options:
Without option:
python example.pyoutputsHello, number is: 0!With option (no value):
python example.py --numberoutputsError: Option '--number' requires an argument.❌With option an value:
python example.py --number 3outputsHello, number is: 3!Expected behaviour
With option (no value):
python example.py --numberoutputsHello, number is: 1!✅The expected behaviour is, as described in the click documentation (see Optional Value) that the option has a
flag_valuewhich is set to1.Or that is how I understand that it should also work.
PD: it works the same way with string and not numbers (so the exact example set in the documentation, I put numbers because it is also my use case.
Environment: