-
First Check
Commit to Help
Example Codeimport typer
def main(some_flag: bool = typer.Option(False, help="help string")):
if some_flag:
print("some_flag was True/Truthy")
if __name__ == "__main__":
run(main) DescriptionIf I run this script from as CLI, then it works as expected, i.e. not providing the However, if I call the function from another python function, then I am aware that I can check for the default value with Operating SystemWindows Operating System DetailsNo response Typer Version0.6.1 Python Version3.8.2 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
Hey there! Yep, that's because Typer only allowed setting the values as the function parameter "default", in that case, for it to work you would have had to pass the parameters manually when calling the function. But now there's support for Annotated, to solve exactly this problem 🎉 import typer
from typing_extensions import Annotated
def main(some_flag: Annotated[bool, typer.Option(help="help string")] = False):
if some_flag:
print("some_flag was True/Truthy")
if __name__ == "__main__":
run(main)
main() It's available in Typer 0.9.0, just released 🚀 |
Beta Was this translation helpful? Give feedback.
Hey there! Yep, that's because Typer only allowed setting the values as the function parameter "default", in that case, for it to work you would have had to pass the parameters manually when calling the function.
But now there's support for Annotated, to solve exactly this problem 🎉
It's available in Typer 0.9.0, just released 🚀