-
Notifications
You must be signed in to change notification settings - Fork 262
Open
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations
Description
I am trying to implement a function that, as the type of one argument, can accept either an Enum or a value of such an enum (because some Python programmers are more used to type strings instead of enum values). Currently I have managed to do the following:
class LinkageCriterion(enum.Enum):
WARD = "ward"
COMPLETE = "complete"
AVERAGE = "average"
SINGLE = "single"
LinkageCriterionLike = Union[
LinkageCriterion,
Literal["ward", "complete", "average", "single"]
]
My question is if there is a way to not repeat myself here, that is, if you can construct a Literal from the values of a given Enum, and if so, how?
schneiderfelipe, tuchandra, kunansy, Exifers, taitsmp and 79 more
Metadata
Metadata
Assignees
Labels
topic: featureDiscussions about new features for Python's type annotationsDiscussions about new features for Python's type annotations