Weird behavior when wrongly combining Annotated
with List
#713
Unanswered
The-Compiler
asked this question in
Questions
Replies: 1 comment 1 reply
-
Actually, I would say the usage is wrong here. Your code would work just fine if you had done the reverse: def test(arg: Annotated[List[str], typer.Argument(help="test")]): # <- yay!
print("test") |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
First Check
Commit to Help
Example Code
Description
On Python 3.8, this results in:
from here:
https://github.com/tiangolo/typer/blob/4c6098f9fe893cbe5536b1cb793ef7dd35bfd7c1/typer/main.py#L834-L836
On newer Python versions, this works, but the
typer.Argument
silently gets dropped. See--help
:as opposed to using
Annotated[List[str], typer.Argument(help="test")]
correctly:The fact that Python 3.9+ fails silently is due to
typing.get_type_hints()
by default stripping metadata there. Thus, when it's called here:https://github.com/tiangolo/typer/blob/4c6098f9fe893cbe5536b1cb793ef7dd35bfd7c1/typer/utils.py#L110
the
Annotated
part gets dropped here:https://github.com/tiangolo/typer/blob/4c6098f9fe893cbe5536b1cb793ef7dd35bfd7c1/typer/utils.py#L164-L166
Operating System
Linux
Operating System Details
No response
Typer Version
0.9.0
Python Version
3.8.18, 3.9.18, 3.11.6
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions