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

Incorrect type hint for param_hint in BadParameter exception #2777

Open
dhdaines opened this issue Sep 12, 2024 · 0 comments
Open

Incorrect type hint for param_hint in BadParameter exception #2777

dhdaines opened this issue Sep 12, 2024 · 0 comments

Comments

@dhdaines
Copy link

The documentation and the type annotations don't quite match for click.BadParameter, specifically for the param_hint argument. The documentation says:

If it is a string it's used as such, if it's a list then each item is quoted and separated.

But the type annotation says:

param_hint: str | None = None

To reproduce, create code like:

raise click.BadParameter("FOOBIE BLETCH", param_hint=["HACKEM", "MUCHE"])

then run mypy on said code.

Expected: mypy gives no error

Actual behaviour: mypy says:

foo.py:2: error: Argument "param_hint" to "BadParameter" has incompatible type "list[str]"; expected "str | None"  [arg-type]

Easy to fix, just need to update the type hint for param_hint to the one already used in _join_param_hints:

cabc.Sequence[str] | str | None

Environment:

  • Python version: 3.11.2
  • 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