Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nicer handling of callable defaults #51

Open
chrisjsewell opened this issue Jul 4, 2023 · 1 comment
Open

Nicer handling of callable defaults #51

chrisjsewell opened this issue Jul 4, 2023 · 1 comment

Comments

@chrisjsewell
Copy link

Currently, if you have an option that sets a callable default, it will simply show the str format of it, e.g. if you have:

def my_default():
    return "hi"

@click.command()
@click.option('-o', default=my_default)
def command(option): ...

it will show as <function my_default at 0x10f0fb040>

Obviously, it would be nice if there was a better representation thanks (or just no default was shown)

@boehmseb
Copy link

boehmseb commented Jan 5, 2024

This becomes a bigger issue if used with a click.Choice because the string representation of the function object is obviously not contained in the allowed values: InvalidSelectValueError: Illegal select value '<function <lambda> at 0x7f426eb0b100>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants