Skip to content

Incorrect names being picked #793

Closed
Closed

Description

@ericfrederich

Docs state By default, the name of the parameter is the first long option defined; otherwise the first short one is used.

The implementation of this is in _parse_decls method of Option which has a line...

possible_names.sort(key=lambda x: len(x[0]))
name = possible_names[-1][1].replace('-', '_').lower()

... currently here

This invocation of list.sort with key= essentially makes every short option equal to each other and every long option equal to each other. The original order they were defined in is subject to change.

In fact... even if it were to maintain that order, the code would actually be grabbing the last long parameter.

Fix coming soon... I'll submit it. I'll change the code to match the docs.

Activity

  1. untitaker commented on May 18, 2017

    @untitaker
    Contributor

    Please also include an example that behaves unexpectedly.

  2. added a commit that references this issue on May 18, 2017
    3b36317
  3. ericfrederich commented on May 18, 2017

    @ericfrederich
    ContributorAuthor

    @untitaker I provided one in the merge request... but I'll re-paste here as well.

    Currently an option defined as...

    @click.option('--ambitious', '--all', '-a', is_flag=True)

    ...will target all instead of ambitious

    I get an error TypeError: batch() got an unexpected keyword argument 'all'

  4. added 4 commits that reference this issue on May 19, 2017
    4cd18db
    3e4abc1
    ac5990f
    f15f425
  5. added a commit that references this issue on May 21, 2017
    ebcbef9
  6. nyanpasu64 commented on Jul 27, 2018

    @nyanpasu64

    When will Click 6.8 be released? I discovered this bug independently, but the fix hasn't been released yet.

  7. added this to the 7.0 milestone on Sep 10, 2018
  8. added 2 commits that reference this issue on Oct 8, 2018
  9. added a commit that references this issue on Oct 29, 2018
  10. locked as resolved and limited conversation to collaborators on Nov 13, 2020
  11. added
    docs
    parsing
    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

    docsparsing

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions