-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Closed
Description
Hello
I have noticed since upgrading to 8.2.2 from 8.2.1 when flag_value is set to a string, and the flag is unset, the value of the flag is "False" (a string not a bool), this causes issues when using the value in conditionals.
Example:
import click
@click.group()
def cli():
pass
@cli.command()
@click.option(
"-a",
"--a-flag",
is_flag=True,
)
@click.option(
"-av",
"--a-flag-with-value",
is_flag=True,
flag_value="hello world",
)
def mycmd(a_flag, a_flag_with_value):
print("a_flag:", a_flag, type(a_flag))
print("a_flag_with_value:", a_flag_with_value, type(a_flag_with_value))
print('a_flag_with_value == "False":', a_flag_with_value == "False")
if a_flag:
print("a_flag is set!")
if a_flag_with_value:
print("a_flag_with_value is set!")
cli()Output running python testclick.py mycmd with 8.2.2:
a_flag: False <class 'bool'>
a_flag_with_value: False <class 'str'>
a_flag_with_value == "False": True
a_flag_with_value is set!
Ideally a_flag_with_value is set! would not be printed.
Output running python testclick.py mycmd with 8.2.1:
a_flag: False <class 'bool'>
a_flag_with_value: None <class 'NoneType'>
a_flag_with_value == "False": False
Environment:
- Python version: 3.10.6 and 3.10.12
- Click version: 8.2.2
Thank you
Metadata
Metadata
Assignees
Labels
No labels