Weird behavior when wrongly combining Annotated
with List
#713
-
First Check
Commit to Help
Example Codefrom typing_extensions import Annotated
from typing import List, get_type_hints
import typer
def test(arg: List[Annotated[str, typer.Argument(help="test")]]): # wrong!
print("test")
if __name__ == "__main__":
print(get_type_hints(test))
typer.run(test) DescriptionOn Python 3.8, this results in:
from here: On newer Python versions, this works, but the
as opposed to using
The fact that Python 3.9+ fails silently is due to https://github.com/tiangolo/typer/blob/4c6098f9fe893cbe5536b1cb793ef7dd35bfd7c1/typer/utils.py#L110 the Operating SystemLinux Operating System DetailsNo response Typer Version0.9.0 Python Version3.8.18, 3.9.18, 3.11.6 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
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.
Actually, I would say the usage is wrong here.
It makes no sense to annotate the item type of the list with the
typer.Argument
description.Your code would work just fine if you had done the reverse: