question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Longest option argument not used as internal/variable name

See original GitHub issue

It seems that with 7.0 the longest option argument isn’t being used as the internal and variable name.

https://github.com/pallets/click/blob/2c622eed402c64e1645db3904c2410f6c05fbf19/docs/parameters.rst#L93-L95

the internal name is generated automatically by taking the longest argument

import click
import click.testing


print(click.__version__)

@click.command()
@click.option(
    '--temp',
    '--temporary',
    'temporary',
)
def good(temporary):
    pass


@click.command()
@click.option(
    '--temp',
    '--temporary',
)
def bad(temporary):
    pass


def click_runner(command):
    print(command.name)
    runner = click.testing.CliRunner()
    result = runner.invoke(
        command,
        [],
        catch_exceptions=False,
    )
    print(result.output)

click_runner(command=good)
click_runner(command=bad)

https://repl.it/@altendky/click-67-unexpected-keyword-argument-1

6.7
good

bad

https://repl.it/@altendky/click-70-unexpected-keyword-argument-1

7.0
good

bad
Traceback (most recent call last):
  File "python", line 37, in <module>
  File "python", line 32, in click_runner
TypeError: bad() got an unexpected keyword argument 'temp'

https://repl.it/@altendky/click-2e856a5-unexpected-keyword-argument

7.0
good

bad
Traceback (most recent call last):
  File "python", line 37, in <module>
  File "python", line 32, in click_runner
TypeError: bad() got an unexpected keyword argument 'temp'

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:31 (19 by maintainers)

github_iconTop GitHub Comments

2reactions
altendkycommented, Oct 23, 2018

It’s kind of tempting to deprecate this ‘feature’ and just say ‘if you have multiple of the longest type of parameter, specify the name’. Or maybe provide a marker so you don’t have to repeat. Maybe '+--the-default' or somesuch? I dunno, explicit over implicit and all. This just seems like a bit of a fiddly mess with little benefit.

1reaction
altendkycommented, Oct 23, 2018

Sorry, make it backwards compatible but fix the situation by deprecating the implicit order-based selection.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing argument as differently named parameter #949 - GitHub
It is possible to pass option as different variable name (e.g. ... becomes the internal parameter name which is also used as variable...
Read more >
Parsing command-line arguments by Getopt::Long • GetoptLong
If the variable is defined as a function before GetoptLong() is called, it is treated as undefined. Please note your option names should...
Read more >
Options (The GNU Awk User's Guide)
GNU-style long options consist of two dashes and a keyword. ... The -v option can only set one variable, but it can be...
Read more >
5. Functions - gigamonkeys
A function's parameter list defines the variables that will be used to hold the arguments passed to the function when it's called. ......
Read more >
Options Settings - R
Invoking options() with no arguments returns a list with the current values of the options. Note that not all options listed below are...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found