-
-
Notifications
You must be signed in to change notification settings - Fork 825
🗑️ Deprecate support for is_flag and flag_value parameters
#987
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
Conversation
is_flag and flag_value parametersis_flag and flag_value parameters
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great! Looks good! 🚀 Thank you! 🙇
|
Hello ! import typer
def main(my_bool: bool = typer.Option(True, is_flag=False)):
print(f"my_bool : {my_bool}")
print(f"type(my_bool) : {type(my_bool)}")
if __name__ == "__main__":
typer.run(main)Which could be used with : > python main.py --my-bool true
my_bool : True
type(my_bool) : <class 'bool'>OR : > python main.py --my-bool false
my_bool : False
type(my_bool) : <class 'bool'>For more details, we use argo workflows to submit scripts, therefore we cannot dynamically create the --my-bool or --not-my-bool string in the argo workflow template. I also thought of using alternative names def main(my_bool: bool = typer.Option(True, "--my-bool_true/--my-bool_false")):And then : > python main.py --my-bool_trueBut this also becomes quite a strange use This would be wonderful if we could get this feature back ! |
|
Wanted to add support for @Plenitude-ai's comment. My team has the exact same use case and limitation about how bool values are dynamically created and passed as args. |
|
I think the original conclusion that In version When Usage: typertest.py [OPTIONS]
╭─ Options ─────────────────────────────────────────────────────────────────╮
│ --my-bool --no-my-bool [default: my-bool] │
│ --help Show this message and exit. │
╰───────────────────────────────────────────────────────────────────────────╯But when Failing to pass an argument to ╭─ Error ────────────────────────────────────────────────────────────────────────╮
│ Option '--my-bool' requires an argument. │
╰────────────────────────────────────────────────────────────────────────────────╯ |
|
Thanks for your reports! Let me look into this (again) and get back to you 🙏 |
|
@svlandeg, thanks for taking another look at this. I'm having a similar issue porting a pure click script to typer. Would be nice to support passing booleans "by value" from the command line and I believe that As it stands, it appears this click annotations not supported out of the box, @click.option(
"--my-bool",
type=bool,
default=False,
)where you pass the value like |
Fixes #986
DeprecationWarningwhenOptionInforeceives a value foris_flagand/orflag_valueTyperOptiondoesn't useflag_valueanymore and itsis_flagis now defined only by looking at whether or notmain_type is boolThese parameters weren't actually functional (cf. #873) and they weren't documented, so I don't think this should be breaking. But it's always difficult to say - users could be relying on unspecified internals... 🫤