Skip to content
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

The flag_value shadows default in click.option() #2610

Open
drunkwcodes opened this issue Sep 17, 2023 · 0 comments
Open

The flag_value shadows default in click.option() #2610

drunkwcodes opened this issue Sep 17, 2023 · 0 comments

Comments

@drunkwcodes
Copy link

drunkwcodes commented Sep 17, 2023

There are two problems:

  1. The flag_value shadows default in click.option()
  2. The default type is omitted, the option converts to str anyway.

About 2., The click docs says in the option section: "If no type is provided, the type of the default value is used."
But it is not True. I have to use type=frozenset to make the option's value not be "frozenset()", which breaks my function iterating it.

And the 1. is the big deal.
I provide my option code below and a minimal reproducer script.
I'm making a venv for Mojo language, and looking at new venv code on cpython.

If click can not fix this, it can not do things like Brett Cannon does in venv cli design. That's not good.
I want scm_ignore_files to be frozenset() if the flag is provided, else it is default to frozenset(["git"]).

Why is default not useful and the flag_value is always used?

@click.option(
    "--without-scm-ignore-files",
    "scm_ignore_files",
    is_flag=True,
    type=frozenset,
    flag_value=frozenset(),
    default=frozenset(["git"]),
    help="Skips adding SCM ignore files to the environment "
    "directory (Git is supported by default).",
)

Thanks for watching!

Environment:

  • Python version: Python 3.10.12
  • Click version: 8.1.7
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant