Skip to content

Custom default label ignored if default is None #1732

@ziima

Description

@ziima

I found out that custom default label is not shown when default is None. In some cases default = None is intentional, but custom default label would be still helpful.

An example with --limit option, with None as default meaning no limit:

import click

@click.command()
@click.option('--limit', type=int, show_default='unlimited')
def main(limit: int):
    print('Limit: {}'.format(limit))

if __name__ == '__main__':
    main()

Expected Behavior

Tell us what should happen.

$ python3 /tmp/foo.py --help
Usage: foo.py [OPTIONS]

Options:
  --limit INTEGER  [default: unlimited]
  --help           Show this message and exit.

Actual Behavior

Tell us what happens instead.

$ python3 /tmp/foo.py --help
Usage: foo.py [OPTIONS]

Options:
  --limit INTEGER
  --help           Show this message and exit.

Default is not shown, making the description less useful.

Environment

  • Python version: 3.9.1
  • Click version: 7.1.2

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions