Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 25 additions & 16 deletions Lib/enum.py
Original file line number Diff line number Diff line change
Expand Up @@ -773,22 +773,31 @@ def __delattr__(cls, attr):
super().__delattr__(attr)

def __dir__(cls):
interesting = set([
'__class__', '__contains__', '__doc__', '__getitem__',
'__iter__', '__len__', '__members__', '__module__',
'__name__', '__qualname__',
]
+ 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__')
if cls._member_type_ is object:
return sorted(interesting)
else:
# return whatever mixed-in data type has
return sorted(set(dir(cls._member_type_)) | interesting)
interesting = set([
'__class__', '__contains__', '__doc__', '__getitem__',
'__iter__', '__len__', '__members__', '__module__',
'__name__', '__qualname__',
] + 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__')

# SGP: Include documented public _sunder_ helpers defined on the Enum class.
# SGP: This makes them discoverable via dir(Enum) so rlcompleter can surface
# SGP: them in REPL completions. (rlcompleter drives dotted-name completion
# SGP: from dir(); _add_alias_/_add_value_alias_ are supported _sunder_ APIs.)
for _n in ("_add_alias_", "_add_value_alias_"):
if _n in cls.__dict__:
interesting.add(_n)

if cls._member_type_ is object:
return sorted(interesting)
else:
# return whatever mixed-in data type has
# SGP: union the mixin's dir() with 'interesting'
return sorted(set(dir(cls._member_type_)) | interesting)
Comment on lines +776 to +800
Copy link
Member

Choose a reason for hiding this comment

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

The indentation is missed up.

Copy link
Author

Choose a reason for hiding this comment

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

I corrected the indentation I thought! OK I guess I am really not good enough...I should not have tried contributing and will first try to improve myself, I am sorry.

Copy link
Member

Choose a reason for hiding this comment

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

Everyone makes such small mistakes, all contributions are welcome:-) I think you accidentally unindented the whole section in 01d3a59


def __getitem__(cls, name):
"""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
dir(Enum) now includes public _sunder_ helpers (_add_alias_, _add_value_alias_) for better REPL completion. (gh-139398)
Loading