How do I pass the None value explicitly? #1340
-
First Check
Commit to Help
Example Codefrom typing import Optional
import typer
def main(
limit: Optional[int] = typer.Option(11),
):
print(limit)
if __name__ == "__main__":
typer.run(main)DescriptionHow do I pass the Operating SystemmacOS Operating System DetailsNo response Typer Version0.7.0 Python VersionPython 3.9.13 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
|
Semantically My proposal is that you either use a special value (for example from typing import Optional
import typer
def main1(
limit: Optional[int] = typer.Option(11, help="A limit value of 0 disables the limit.")
):
if limit > 0:
print(limit)
else:
print("unlimited")
def main2(
limit: Optional[int] = 11,
disable_limit: bool = typer.Option(False, "--disable-limit")
):
if disable_limit:
limit = None
print(limit)
if __name__ == "__main__":
typer.run(main1) |
Beta Was this translation helpful? Give feedback.
-
|
Update here: with custom parsers, you should be able to implement this as of typer 0.8.0! Usage: The name of the parser is even displayed in the help string: You could modify the |
Beta Was this translation helpful? Give feedback.
Update here: with custom parsers, you should be able to implement this as of typer 0.8.0!
Usage:
The name of the parser is even displayed in the help string: