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

Add EnumChoice type #2272

Closed
wants to merge 7 commits into from
Closed

Add EnumChoice type #2272

wants to merge 7 commits into from

Conversation

dzcode
Copy link
Contributor

@dzcode dzcode commented May 2, 2022

  • Add EnumChoice ParamType that inherits from the Choice type. It can take an enum.Enum and use it's keys or values as options that can then be mapped back to the enum itself.
  • Allows enum keys or values to be used as the choices

Example Usage:

    class MockEnum(Enum):
        foo = 1
        bar = 2
        baz = 3

    @click.argument("method", type=click.EnumChoice(MockEnum))
    def cli(method):
        click.echo(method)

Fixes #605

Checklist:

  • Add tests that demonstrate the correct behavior of the change. Tests should fail without the change.
  • 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.
  • Add .. versionchanged:: entries in any relevant code docs.
  • Run pre-commit hooks and fix any issues.
  • Run pytest and tox, no tests failed.

@dzcode
Copy link
Contributor Author

dzcode commented May 2, 2022

Closing in favor of #2210

@dzcode dzcode closed this May 2, 2022
@davidism
Copy link
Member

davidism commented May 4, 2022

Sorry for the duplicated effort, this PR looks good too.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 19, 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.

Python Enum support for click.Choice
2 participants