Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implicit order of choosing parameter names changed in 6.x, but still inconsistent with documentation #1147

Closed
amiryal opened this issue Oct 15, 2018 · 1 comment

Comments

@amiryal
Copy link

amiryal commented Oct 15, 2018

From the documentation:

If all names for a parameter contain dashes, the internal name is generated automatically by taking the longest argument and converting all dashes to underscores.

However, in the implementation, when the possible names are sorted, it’s only for the purpose of grouping them “long options first” — meaning “options with two dashes first”, not “longest name first”.

See current master:

possible_names.sort(key=lambda x: -len(x[0])) # group long options first

And compare with branch 5.x:
possible_names.sort(key=lambda x: len(x[0]))

Between version 5.x and 6.x, the implicit (misdocumented) order had changed, which broke my script.

This bug manifests only when multiple long parameter (option) names are specified, i.e.:

@click.option('--shorter', '--longer-option')

…in which case different versions of Click would choose a different name between shorter and longer_option instead of always choosing longer_option as suggested in the documentation.

@davidism
Copy link
Member

Duplicate of #1140

@davidism davidism marked this as a duplicate of #1140 Oct 15, 2018
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants