-
-
Notifications
You must be signed in to change notification settings - Fork 33k
gh-139398: Make dir(Enum) include public _sunder_ helpers for REPL completions #139418
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
a526094
7ab184a
d7f1af9
01d3a59
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The indentation is missed up. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. There was a problem hiding this comment. Choose a reason for hiding this commentThe 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): | ||
""" | ||
|
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) |
Uh oh!
There was an error while loading. Please reload this page.