Option(...) make options as required but not working #1345
-
First Check
Commit to Help
Example Codeimport typer
from typer import (
Option
)
def main(
opt1: str = Option(...) # required option
):
# must not be printed as None but print None
print(opt1)
if __name__ == '__main__':
typer.run(main) Description(I’m not a native English speaker, so please excuse any awkward phrasing.) I tested this with Typer 0.17.4, and I noticed that neither When I tested the same behavior with Click, it worked as expected. Looking into how Typer and Click handle this internally, I found the following: In Click, an option raises a # raise MissingParameter when required and value == UNSET
if self.required and self.value_is_missing(value):
raise MissingParameter(ctx=ctx, param=self) According to Typer’s documentation, using ellipsis ( However, when using ellipsis, because of the logic in Typer’s As a result, the Click condition above is never satisfied. If I try forcing it with Operating SystemmacOS Operating System DetailsNo response Typer Version0.17.4 Python Version3.10.12 Additional ContextNo response |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
I think you're probably running into the same issue over here #1334 |
Beta Was this translation helpful? Give feedback.
-
This is now fixed and released:
|
Beta Was this translation helpful? Give feedback.
I think you're probably running into the same issue over here #1334