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 — gh-128080: remove unnecessary `__init__` method from Enum by tungol · Pull Request #128081 · python/cpython

Conversation

@tungol

@tungol tungol commented Dec 18, 2024 •
edited by bedevere-app Bot
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

Enum gained an __init__ method in 3.11 which just passes:

    def __init__(self, *args, **kwds):
        pass

That was added in #30582. One person questioned it at the time, but there was no response. The best I can figure is that it was related to special handling of __init__ in EnumType.__dir__, which you can see here:

cpython/Lib/enum.py

Lines 768 to 779 in 3852269

def __dir__(cls):
# TODO: check for custom __init__, __new__, __format__, __repr__, __str__, __init_subclass__
# on object-based enums
if cls._member_type_ is object:
interesting = set(cls._member_names_)
if cls._new_member_ is not object.__new__:
interesting.add('__new__')
if cls.__init_subclass__ is not object.__init_subclass__:
interesting.add('__init_subclass__')
for method in ('__init__', '__format__', '__repr__', '__str__'):
if getattr(cls, method) not in (getattr(Enum, method), getattr(Flag, method)):
interesting.add(method)

That special handling of __init__ was removed by #30677 prior to 3.11 being released, which leaves no plausible function to Enum.__init__ that I can see. It muddies introspection of the type, so I think we should remove it if that's really the case.

  • Issue: It seems that enum.Enum.__init__ serves no purpose #128080

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
@tungol
remove unnecessary __init__ method from Enum
4c7a9a8
@tungol
tungol requested a review from ethanfurman as a code owner December 18, 2024 21:09
@bedevere-app bedevere-app Bot mentioned this pull request Dec 18, 2024
It seems that enum.Enum.__init__ serves no purpose #128080
Closed
@bedevere-app bedevere-app Bot added the awaiting review label Dec 18, 2024
@ZeroIntensity ZeroIntensity added the skip news label Dec 19, 2024
@ZeroIntensity
Merge branch 'main' into enum_init
3b2813b
@ZeroIntensity

ZeroIntensity commented Dec 19, 2024

Copy link
Copy Markdown
Member

I've fixed the failing macOS CI for you :)

All reactions

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

ethanfurman
ethanfurman approved these changes Dec 19, 2024
View reviewed changes
@bedevere-app bedevere-app Bot added awaiting merge and removed awaiting review labels Dec 19, 2024
@ethanfurman
ethanfurman merged commit c14db20 into python:main Dec 19, 2024
@bedevere-app bedevere-app Bot removed the awaiting merge label Dec 19, 2024
@tungol
tungol deleted the enum_init branch December 20, 2024 00:20
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Dec 23, 2024
@tungol @ZeroIntensity @srinivasreddy
pythongh-128080: remove unnecessary __init__ method from Enum (pyth…
356306e
…onGH-128081)

remove unnecessary __init__ method from Enum

Co-authored-by: Peter Bierma <[email protected]>
srinivasreddy pushed a commit to srinivasreddy/cpython that referenced this pull request Jan 8, 2025
@tungol @ZeroIntensity @srinivasreddy
pythongh-128080: remove unnecessary __init__ method from Enum (pyth…
343439f
…onGH-128081)

remove unnecessary __init__ method from Enum

Co-authored-by: Peter Bierma <[email protected]>
@anakin87 anakin87 mentioned this pull request Mar 23, 2026
Python 3.14 incompatibility IBM/watsonx-ai-python-sdk#11
Closed
This was referenced Sep 22, 2026
fix: remove __init__ override from heat_system.py for python >=3.14 open-energy-transition/open-tyndp#990
Merged
fix: remove __init__ override from heat_system.py for python >=3.14 PyPSA/pypsa-eur#2304
Merged
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@ethanfurman ethanfurman ethanfurman approved these changes

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

skip news

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

3 participants

@tungol @ZeroIntensity @ethanfurman
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.