Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Unexpected behavior change in subclassing Enum class as of 3.11 #103479

Copy link
Copy link
Closed
@sadra-barikbin

Description

@sadra-barikbin
Issue body actions

I had a question regarding changes in subclassing Enum in 3.11. As of 3.11, if enum class has a mixin parent apart from Enum which has defined __init__ or __new__, member._value_ is set to be another instance of the mixin class
unless user defines __new__ in the enum class and set _value_. However user naturally expects _value_ to be the value assigned to the member in class definition. In the example below

class mixin:
  def __init__(self):
    pass

class CustomEnum(mixin, Enum):
  MEMBER = "member"

CustomEnum.MEMBER is an instance of mixin and CustomEnum.MEMBER.value is another instance of it (with different id), while it was expected that CustomEnum.MEMBER.value would be "member". What has been the rationale for this change?

By the way, this change is not noted in python docs enumeration page.

Linked PRs

Metadata

Metadata

Assignees

Labels

docsDocumentation in the Doc dirDocumentation in the Doc dir

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions

    Morty Proxy This is a proxified and sanitized view of the page, visit original site.