8000 Type `_order_` field in `Enum` · Issue #11715 · python/mypy · GitHub
[go: up one dir, main page]

Skip to content

Type _order_ field in Enum #11715

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

Open
sobolevn opened this issue Dec 11, 2021 · 1 comment
Open

Type _order_ field in Enum #11715

sobolevn opened this issue Dec 11, 2021 · 1 comment

Comments

@sobolevn
Copy link
Member
sobolevn commented Dec 11, 2021

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.

@sobolevn
Copy link
Member Author

To fix this I need changes from #11249 to be merged.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants
0