GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Unexpected behavior change in subclassing `Enum` class as of 3.11 · Issue #103479 · python/cpython

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

New issue
Copy link
New issue
Copy link
Closed
Closed
Unexpected behavior change in subclassing Enum class as of 3.11#103479
Copy link
Assignees
ethanfurman
Labels
docsDocumentation in the Doc dirDocumentation in the Doc dir

Description

@sadra-barikbin
sadra-barikbin
opened on Apr 12, 2023
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

  • gh-103479: [Enum] require __new__ to be considered a data type #103495
  • [3.11] gh-103479: [Enum] require __new__ to be considered a data type (GH-103495) #103514

Activity

  1. ethanfurman
    self-assigned this
    on Apr 12, 2023
  2. arhadthedev
    added
    docsDocumentation in the Doc dirDocumentation in the Doc dir
    on Apr 12, 2023
  3. ethanfurman
    added 2 commits that reference this issue on Apr 13, 2023

    gh-103479: [Enum] require __new__ to be considered a data type (GH-10…

    a6f9594

    [3.11] pythongh-103479: [Enum] require __new__ to be considered a da…

    ab60fdd
  4. carljm
    added a commit that references this issue on Apr 13, 2023

    Merge branch 'main' into superopt

    9384106
  5. ethanfurman
    added a commit that references this issue on Apr 13, 2023

    [3.11] gh-103479: [Enum] require __new__ to be considered a data type (…

    3b929a7
  6. ethanfurman commented on Apr 13, 2023

    @ethanfurman
    ethanfurman
    on Apr 13, 2023
    Member
    More actions

    Thank you for the bug report; this is now fixed.

    Reacted by Sadra Barikbin
  7. ethanfurman
    closed this as completedon Apr 13, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

  • @ethanfurman
    ethanfurman

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

    You are visitor 01402503 — GeezerVison does not store the pages you look up.
    Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.