Skip to content

Truthiness of Option(False) should be False #597

Answered by tiangolo
khaume asked this question in Questions
Discussion options

You must be logged in to vote

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 🚀

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by tiangolo
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Question or problem investigate
2 participants
Converted from issue

This discussion was converted from issue #462 on May 02, 2023 06:25.