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

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 <[email protected]>
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.

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