Feature request: support `Enum`s in `inputMenu` and `inputChoice`
AlexWaygood opened this issue · 0 comments
AlexWaygood commented
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 Enum
s 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.