Skip to content

Conversation

RafaelWO
Copy link
Contributor

@RafaelWO RafaelWO commented Oct 12, 2025

This change adds the sunder names _generate_next_value_ and _missing_ to the __dir__ method of EnumType and Enum.
In Addition, The instance level sunder names _add_alias_ and _add_value_alias_ are added to Enum.__dir__.

With the sunder names exposed in the dir() method, the REPL autocomplete will also show them.

Note: This PR is based on the first attempt to address this issue: #139418

Preview:

>>> from enum import Enum
>>> Enum._
Enum._add_member_(                  Enum._create_(               Enum._find_new_(         --> Enum._missing_(
Enum._check_for_existing_members_(  Enum._find_data_repr_(   --> Enum._generate_next_value_(  
Enum._convert_(                     Enum._find_data_type_(       Enum._get_mixins_(           
>>> class Foo(Enum):
...     BAR = 1
... 
>>> Foo.BAR._   # all of the below are "new"
Foo.BAR._add_alias_(            Foo.BAR._add_value_alias_(      Foo.BAR._generate_next_value_(  Foo.BAR._missing_(

📚 Documentation preview 📚: https://cpython-previews--139985.org.readthedocs.build/

Comment on lines +5152 to +5155
Attribute(name='_missing_', kind='class method',
defining_class=Enum, object=self.Color._missing_),
Attribute(name='_generate_next_value_', kind='static method',
defining_class=self.Color, object=staticmethod(self.Color._generate_next_value_)),
Copy link
Contributor Author

@RafaelWO RafaelWO Oct 12, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried to adjust this test to expect the new attributes, but I wasn't able to get the test to pass. I guess I need some help here 🙂 thanks!

./python -m unittest -v test.test_enum.TestStdLib.test_inspect_classify_class_attrs

Comment on lines 1 to 2
Add supported \_sunder\_ names to __dir__() method of Enum to support them
in REPL autocompletion.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is restructured text.

Suggested change
Add supported \_sunder\_ names to __dir__() method of Enum to support them
in REPL autocompletion.
Add supported ``_sunder_`` names to the :func:`dir` method of the :mod:`Enum` module
to support them in :term:`REPL` autocompletion.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the suggestion! I fixed it

RafaelWO and others added 2 commits October 12, 2025 09:41
This change adds the sunder names `_generate_next_value_`
and `_missing_` to the `__dir__` method of `EnumType` and `Enum`.
In Addition, The instance level sunder names
`_add_alias_` and `_add_value_alias_` are added to `Enum.__dir__`.

With the sunder names exposed in the `dir()` method,
the REPL autocomplete will also show them.

Co-Authored-By: SimonGPrs <107691772+SimonGPrs@users.noreply.github.com>
This change highlights which of the attributes were expected
versus were actually there.
@StanFromIreland
Copy link
Member

Please don't force push, it complicates reviewing. All commits are squashed at the end anyway.

@@ -0,0 +1,2 @@
Add supported ``_sunder_`` names to the :func:`dir` method of the :mod:`Enum` module
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
Add supported ``_sunder_`` names to the :func:`dir` method of the :mod:`Enum` module
Add supported ``_sunder_`` names to the :func:`dir` method of the :mod:`enum` module

Apologies for this omission in my previous suggestion, the directives are case-sensitive.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No worries, fixed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants