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

Feature request: support Enums in inputMenu and inputChoice #22

Open
AlexWaygood opened this issue Aug 24, 2021 · 0 comments
Open

Feature request: support Enums in inputMenu and inputChoice #22

AlexWaygood opened this issue Aug 24, 2021 · 0 comments

Comments

@AlexWaygood
Copy link

If I'm presenting a user with a list of choices, this works really nicely:

from pyinputplus import inputMenu

CHOICES = ('Go left', 'Go right')

inputMenu(choices=CHOICES, prompt='Pick a direction')

It would be really nice, however, to do this instead, which isn't supported:

from enum import Enum
from pyinputplus import inputMenu


class Choices(str, Enum):
    one = 'Go left'
    two = 'Go right'


inputMenu(choices=Choices, prompt='Pick a direction')

Enum classes are iterable, so will pass an isinstance(<enum_cls>, collections.abc.Iterable) test. But they're not, strictly speaking, sequences, which means this line raises an error if I try to feed in an Enum of choices.

Would it be possible to support Enums in inputMenu and inputChoices? I'd be happy to submit a PR if it would be helpful, but I don't know whether changing the validation function in pysimplevalidate would have unintended consequences.

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