typer icon indicating copy to clipboard operation
typer copied to clipboard

Deprecate support for `is_flag` and `flag_value` parameters

Open svlandeg opened this issue 1 year ago • 1 comments

Privileged issue

  • [X] I'm @tiangolo or he asked me directly to create an issue here.

Issue Content

Typer's code base currently contains is_flag and flag_value parameters like Click does. However, the current behaviour is inconsistent with Click's behaviour, and not documented.

In discussion with @tiangolo, we've come to the conclusion that these parameters are pretty confusing overall to work with. There are essentially two defaults (one set in code, and one set by flag_value) and then an option to set an arbitrary value to something that is a "flag". We feel that any behaviour obtained by this combination of parameters can probably be achieved easily with some internal logic and more straightforward (and properly typed) options/arguments.

As such, we've decided to remove these options from the code base as they're not really functional right now anyway.

svlandeg avatar Sep 13 '24 08:09 svlandeg

Related discussions:

  • https://github.com/fastapi/typer/discussions/608
  • https://github.com/fastapi/typer/discussions/873
  • https://github.com/fastapi/typer/pull/872

svlandeg avatar Sep 13 '24 09:09 svlandeg

We feel that any behaviour obtained by this combination of parameters can probably be achieved easily with some internal logic and more straightforward (and properly typed) options/arguments.

Can you please show us how to do this?

I need to handle --my_arg whose default is 'hello':

app
# my_arg is None or False
app --my_arg
# my_arg = hello
app --my_arg bye
# my_arg = bye

Which I can do easily with argparse and I believe with click too.

alanwilter avatar Sep 17 '25 08:09 alanwilter