You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It seems Typer does not check duplicate short or long Option names.
Considering the code above, this output can be seen:
python dupe-options.py --help
Usage: dupe-options.py [OPTIONS]
8000
╭─ Options ────────────────────────────────────────────────────────────╮
│ --first-name -n TEXT First name [default: John] │
│ --surname -n TEXT Surname [default: Doe] │
│ --first-name -c TEXT Title [default: X.] │
│ --help Show this message and exit. │
╰──────────────────────────────────────────────────────────────────────╯
# 🆗 default values, works as expected
python dupe-options.py
X. John Doe
# 🆗 using long name, works as expected
python dupe-options.py --surname Smith
X. John Smith
# ⚠️ oops, using short name, sets "surname" instead of# "first name" as `surname...Option('-n') is defined last
python dupe-options.py -n Murphy
X. John Murphy
# 🆗 using short name sets the "title"
python dupe-options.py -c Hon.
Hon. John Doe
# ⚠️ oops, using "--first-name" sets "title" not "first name"# as title...Option("--first-name") is defined last
cmd [7] | python dupe-options.py --first-name Hon.
Hon. John Doe
Typer takes the last-defined option name (short or long) as the corresponding key for each Annotated function argument.
This bit me today where I had many options with defaults and had a short-name defined twice by accident but Typer did not complain.
Then I was surprised my first-defined option did not get set as expected.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
First Check
Commit to Help
Example Code
Description
If I could I would have raised this as a bug.
It seems Typer does not check duplicate short or long Option names.
Considering the code above, this output can be seen:
Typer takes the last-defined option name (short or long) as the corresponding key for each Annotated function argument.
This bit me today where I had many options with defaults and had a short-name defined twice by accident but Typer did not complain.
Then I was surprised my first-defined option did not get set as expected.
Operating System
Linux
Operating System Details
No response
Typer Version
0.15.2
Python Version
Python 3.10.12
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions