FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-139398: Add supported sunder names to Enum `__dir__` for REPL completions by RafaelWO · Pull Request #139985 · python/cpython · GitHub

/ cpython Public

gh-139398: Add supported sunder names to Enum __dir__ for REPL completions - #139985

Merged
ethanfurman merged 7 commits into
python:mainfrom
RafaelWO:fix/enum-dir
May 28, 2026
Merged

gh-139398: Add supported sunder names to Enum __dir__ for REPL completions#139985
ethanfurman merged 7 commits into
python:mainfrom
RafaelWO:fix/enum-dir

Conversation

RafaelWO commented Oct 12, 2025
edited
Loading

Copy link
Copy Markdown
Contributor

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 thread Lib/test/test_enum.py Outdated
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.

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown

This PR is stale because it has been open for 30 days with no activity.

github-actions Bot added the stale Stale PR or inactive for long period of time. label Apr 30, 2026
The problem was that `_generate_next_value_` is a staticmethod and thus
the expected object is in the `__dict__` of the `Color` class.

read-the-docs-community Bot commented May 25, 2026
edited
Loading

Copy link
Copy Markdown

Copy link
Copy Markdown
Contributor Author

I guess I have to update (via merge) this branch with changes from main to get the tests pass, right?

Copy link
Copy Markdown
Contributor Author

Thanks for updating my branch, @ethanfurman! Any idea how we can fix the failing docs test? 🤔

ethanfurman merged commit baf11a4 into python:main May 28, 2026
56 checks passed
RafaelWO deleted the fix/enum-dir branch June 20, 2026 10:06
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

stale Stale PR or inactive for long period of time.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants


Back | FazBrowse Home | New Git URL