Using Annotated on Lists leads to crash #861
-
First Check
Commit to Help
Example Codeimport typer
from typing import List
from typing_extensions import Annotated
app = typer.Typer()
@app.command()
def test1(test_list: List[int] = typer.Option(default=[1, 2, 3, 4])) -> None:
for i in test_list:
print(i)
@app.command()
def test2(test_list: Annotated[List[int], typer.Option(default=[1, 2, 3, 4])]) -> None:
for i in test_list:
print(i)
app()DescriptionWhile trying to work around this problem, I ran into a new one. I have (I think) used If I comment out The traceback suggests the problem might be within Click, but I'm unsure: Operating SystemmacOS Operating System DetailsNo response Typer Version0.9.4 Python Version3.11.7 Additional ContextSimilar issues: |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 7 replies
-
|
Hi! You have to declare the default value slightly differently with |
Beta Was this translation helpful? Give feedback.
-
|
I think I have a similar situation here. The following code runs fine when using typer 0.16 and pinning click to <8.2 but fails with def get_hashed_default() -> bool:
config = Config.from_cmdargs() # This needs typer initialized to work. So we need the default to be a callable.
return config.hash_subject_ids
@app.command
def foo(hash_subject_ids: Annotated[bool, typer.Option(
help='Whether to hash the subject IDs. Overrides the `hash_subject_ids` setting.',
default_factory=get_hashed_default,
show_default=False,
),
]
) |
Beta Was this translation helpful? Give feedback.
Hi!
You have to declare the default value slightly differently with
Annotated. This should work as expected: