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

Improve type hints #2212

Merged
merged 1 commit into from
Mar 17, 2022
Merged

Improve type hints #2212

merged 1 commit into from
Mar 17, 2022

Conversation

matejcik
Copy link
Contributor

This PR improves the typpe annotation on @command decorator so that when cls is submitted, the return value is an instance of cls.

In addition, as a small tweak, I lowered the requirement on choices of Choice to Collection -- we only need iteration and length. This way Choice(choices=somedict.keys()) is valid.

Checklist:

  • (n/a) Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • (n/a) Add or update relevant docs, in the docs folder and in code.
  • Add an entry in CHANGES.rst summarizing the change and linking to the issue.
  • (n/a) Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@@ -234,7 +234,7 @@ class Choice(ParamType):

name = "choice"

def __init__(self, choices: t.Sequence[str], case_sensitive: bool = True) -> None:
def __init__(self, choices: t.Collection[str], case_sensitive: bool = True) -> None:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please revert this. Requiring a sequence was deliberate on my part, as the order may matter for display purposes.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

easy enough; force-pushed back to a0bbbf2

@davidism davidism merged commit 5ba2320 into pallets:main Mar 17, 2022
@davidism davidism added this to the 8.1.0 milestone Mar 17, 2022
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Apr 1, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Incorrect type hint when @command uses a custom class
2 participants