How can I create an annotated argument without a default value? #616
-
First Check
Commit to Help
Example Code# First example on https://typer.tiangolo.com/tutorial/options/required/
import typer
from typing_extensions import Annotated
def main(name: str, lastname: Annotated[str, typer.Option()]):
print(f"Hello {name} {lastname}")
if __name__ == "__main__":
typer.run(main) DescriptionThe example code doesn't work, throwing the following exception saying that Option() needs a default argument.
Ultimately, I'm trying to create a Typer command that takes a required pathlib.Path argument for which there is no sane default value. I could make one up, even use a fake location, but I feel this should be possible. Operating SystemLinux Operating System DetailsUbuntu 20.04 Typer Version0.4.2 Python Version3.8.10 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Probably some terminology miscommunication here, but If the argument has a default value, then it is an optional argument, is it not? |
Beta Was this translation helpful? Give feedback.
Annotated
, yet you ask forAnnotated
. If you want to useAnnotated
I would suggest that you upgrade to 0.9.0+Annotated
argument with a default value (i.e. an optional argument) can be found in the docsProbably some terminology miscommunication here, but If the argument has a default value, then it is an optional argument, is it not?