-
-
Notifications
You must be signed in to change notification settings - Fork 684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do I pass the None value explicitly? #530
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) |
The default value for --limit configured in our typer.Option is None; however, users cannot explicitly set the value to None: fastapi/typer#530 Closes: #192
The default value for --limit configured in our typer.Option is None; however, users cannot explicitly set the value to None: fastapi/typer#530 Closes: #192
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 |
First Check
Commit to Help
Example Code
Description
How do I pass the
None
value for anOptional
argument that has a non-None
default value?Operating System
macOS
Operating System Details
No response
Typer Version
0.7.0
Python Version
Python 3.9.13
Additional Context
No response
The text was updated successfully, but these errors were encountered: