Skip to content

Type _order_ field in Enum #11715

@sobolevn

Description

@sobolevn

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.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions