Type `_order_` field in `Enum`
Open
Nobody has claimed this yet.
feature
topic-enum
- Dominant language
- Python
- Stars
- 20.6k
- Forks
- 3.3k
- PR merge metrics
- PR metrics pending
Description
Right now this code passes type checking:
from enum import Enum
class E(Enum):
_order_ = 'X Y Z' # Should be 'X Y'
X = 1
Y = 2
But, in runtime it fails:
» python out/ex.py
Traceback (most recent call last):
File "/Users/sobolev/Desktop/mypy/out/ex.py", line 3, in <module>
class E(Enum):
File "/Users/sobolev/.pyenv/versions/3.10.0/lib/python3.10/enum.py", line 348, in __new__
raise TypeError('member order does not match _order_')
TypeError: member order does not match _order_
We need to check that _order_ field is valid.
This can be a great addition to my "better Enums" series of PRs.
Contributor guide
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 tracing mypy's handling of Python Enum class bodies and reproduce the issue's example with the mismatched _order_ value. The work is done when type checking reports an invalid member order while accepting a matching order, with focused tests covering both cases.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 35/100