You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
show_default attempts to print lambdas when using dynamic defaults #844
#!/usr/bin/env pythonimportclickfromdatetimeimportdate@click.command()@click.option('--day', help="choose the day of the week",default=lambda: date.today().strftime("%A"), show_default=True)defmain(day):
print"Hello world! It's a wonderful {}.".format(day)
if__name__=='__main__':
main()
We get the correct default value when running the script:
$ ./hello.py
Hello world! It's a wonderful Tuesday.
However, the help text tries to print the lambda:
$ ./hello.py --help
Usage: hello.py [OPTIONS]
Options:
--day TEXT choose the day of the week [default: <function <lambda> at
0x109c028c0>]
--help Show this message and exit.
I see. We should prevent usage of show_default=True when the default is dynamic. The correct way to document a dynamic default is to describe it in the help text IMO (not evaluate it).
On 31 August 2017 16:25:48 GMT+02:00, Wilfred Hughes ***@***.***> wrote:
So users can see the current value. I use this for expanding `~/foo` to
`/home/wilfred/foo`, and I'd like to show the path in my help message.
Click can't understand what an arbitrary lambda expression does, and I
can already describe how it's calculated in my argument summary.
--
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
#844 (comment)
--
Sent from my Android device with K-9 Mail. Please excuse my brevity.
Activity
untitaker commentedon Aug 29, 2017
I see. We should prevent usage of
show_default=Truewhen the default is dynamic. The correct way to document a dynamic default is to describe it in the help text IMO (not evaluate it).Wilfred commentedon Aug 30, 2017
Is there any downside to evaluating it?
I couldn't see any way of defining a dynamic help text, which is what I'd want in this case if click didn't evaluate my default.
untitaker commentedon Aug 30, 2017
Why would you want to evaluate it? That is less informative than describing how this value is calculated.
Wilfred commentedon Aug 31, 2017
So users can see the current value. I use this for expanding
~/footo/home/wilfred/foo, and I'd like to show the path in my help message.Click can't understand what an arbitrary lambda expression does, and I can already describe how it's calculated in my argument summary.
untitaker commentedon Aug 31, 2017
blueyed commentedon Nov 28, 2017
Duplicate of #547.
Better handling of help text for dynamic default option values for pa…
Better handling of help text for dynamic default option values for pa…