Literal of enum values
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 1.8k
- Forks
- 302
- Avg merge
- 23h
- Merged PRs (30d)
- 8
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?
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by checking the Python typing specification and the behavior of Literal with Enum values. Compare the requested LinkageCriterionLike pattern with current typing support, then document whether enum values can be derived automatically or what limitation remains.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- tooling
- Issue type
- Feature
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100