-
-
Notifications
You must be signed in to change notification settings - Fork 1.5k
Open
Labels
Description
In upgrading from click 7.1.2 to 8.0.1, our click-based CLI started failing with type errors. We have click options whose default values are classes, and as of 8.0.1 they're being converted to strings.
This script is able to reproduce the behavior change:
import click
class Class1:
pass
class Class2:
pass
@click.command()
@click.option("--cls1", "config_cls", flag_value=Class1, default=True)
@click.option("--cls2", "config_cls", flag_value=Class2)
def test(config_cls):
print(config_cls)
print(type(config_cls))
if __name__ == "__main__":
test()Behavior with click 7.1.2:
# pip freeze | grep click
click==7.1.2
# python test.py
<class '__main__.Class1'>
<class 'type'>
Behavior with 8.0.1:
# pip freeze | grep click
click==8.0.1
# python test.py
<class '__main__.Class1'>
<class 'str'>
The type of config_cls should be the class we specified, not 'str'.
Environment:
- Python version: 3.9
- Click version: 8.0.1
MHannila, kimvais, wrcYuri, aleksey-sergey and iFreilicht