Skip to content

show_default attempts to print lambdas when using dynamic defaults #844

@Wilfred

Description

@Wilfred

Given the code:

#!/usr/bin/env python

import click
from datetime import date


@click.command()
@click.option('--day', help="choose the day of the week",
              default=lambda: date.today().strftime("%A"), show_default=True)
def main(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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions