Skip to content

show_default and default_map don't play nice together #1548

Closed

Description

@ewjoachim
#!/usr/bin/env python
import click

@click.command(context_settings={
    "show_default": True, "default_map": {"a": "b"}
})
@click.option("-a", default="c")
def func(a):
    print(a)

if __name__ == "__main__":
    func()
$ # This is expected
$ ./cli.py
b
$ # This is not (default should be b)
$ ./cli.py --help
Usage: cli.py [OPTIONS]

Options:
  -a TEXT  [default: c]
  --help   Show this message and exit.  [default: False]

Expected Behavior

I expect the default shown to be identical to the one being used.

Actual Behavior

The default shown was the value provided as default, without taking the default_map into account

Environment

  • Python version: 3.7
  • Click version: click==7.1.2

Activity

  1. ewjoachim commented on May 9, 2020

    @ewjoachim
    ContributorAuthor

    I may be able to make a failing test or a PR if you point me to the right direction. Would calling lookup_default instead of .default in this line be enough ?

    default_string = self.default

  2. davidism commented on May 9, 2020

    @davidism
    Member

    Seems plausible, happy to review a PR.

  3. ewjoachim commented on May 9, 2020

    @ewjoachim
    ContributorAuthor

    Ok, I'll try to remember to communicate here whether it happens or not. If I have neither said nor committed anything by May 17th, assume I have forgotten about it and you're free to go :)

  4. ewjoachim commented on May 9, 2020

    @ewjoachim
    ContributorAuthor

    Yay, done :)

  5. added this to the 8.0.0 milestone on Oct 12, 2020
  6. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  7. added
    help outputHelp text formatting, layout, and --help rendering
    on Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    help outputHelp text formatting, layout, and --help rendering

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions