-
-
Notifications
You must be signed in to change notification settings - Fork 31.1k
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
Enum's dir() does not contain inherited members #89698
Comments
For example: >>> from enum import *
>>> class E(IntEnum):
... x = 1
...
>>> dir(E)
['__class__', '__doc__', '__members__', '__module__', 'x']
>>> E.from_bytes
<built-in method from_bytes of EnumType object at 0x559d47415ce0>
>>> E.to_bytes
<method 'to_bytes' of 'int' objects>
>>> E.numerator
<attribute 'numerator' of 'int' objects>
>>> E.__add__
<slot wrapper '__add__' of 'int' objects> There are methods and attributes inherited from int, but they are not shown in dir(). As result they are absent in help() and completion does not work for them. |
I had a go at writing a patch for The patch is a fair way more complex than the the existing code, however. |
Looks interesting, thank you for the patch. |
There may be a simple error (superfluous .__class__), but I am not sure. BTW, why use mro() instead of __mro__? Most code use __mro__. |
Would there be interest in me submitting a PR along these lines? ----
Er, no reason, really. To be honest, I've never really understood why Python has both. |
PR 29316 looks complicated. First of all, why do Enum needs a custom __dir__? What is wrong with the default implementation? |
Enums have had a custom dir() from the beginning, partly because they are not standard objects and do not follow standard rules. The question posed by this issue is whether Enums with mixed-in data types should show the inherited methods, and if yes, should it also show inherited I'm inclined to say yes for the normal inherited methods, I'm not sure about inherited |
I would argue it's quite important for But, I agree that my first draft of this PR is more complex than I'd like it to be. |
Fixed in 3.11. Pure enums have a few more dir() entries now; mixed enums now show all inherited methods/attributes -- members still do not show up in member dirs (this is a good thing). |
dir()
#29316Note: these values reflect the state of the issue at the time it was migrated and might not reflect the current state.
Show more details
GitHub fields:
bugs.python.org fields:
The text was updated successfully, but these errors were encountered: