Skip to content

Defining _order_ in an enum class rejected #11699

Closed
@JukkaL

Description

@JukkaL

This generates an error, even though it's valid:

from enum import Enum

class E(Enum):
    _order_ = 'X Y'  # Cannot override writable attribute "_order_" with a final one
    X = 1
    Y = 2

According to the docs, _order_ is a somewhat magical attribute, but it's okay to define it.

The error started happening as a side effect of #10852.

It looks like _order_ actually isn't a valid attribute at runtime, so a potential fix would be to remove it from typeshed. If we want to do this right, we should also remove an explicit definition from the TypeInfo, since it's not available at runtime.

@sobolevn What do you think?

This is a regression, so marking as high priority.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions