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
'__new__' is never shown in dir(SomeEnum)
#90427
Comments
Right now But, this line is problematic: https://github.com/python/cpython/blame/46e4c257e7c26c813620232135781e6c53fe8d4d/Lib/enum.py#L656 Why? Because This behavior is also not tested. So, my proposal is: let's always remove this method from
I guess being consistent here (we don't show I will send a PR that removes these two lines in a moment! Any other ideas are much appreciated! Related: |
Thanks, Nikita! My bad for not adding tests for __new__ in PR 29316. To confirm: yes, my idea in PR 29316 was that "__new__" (along with most enum dunders) should not show up in the output of dir(Enum), but should show up in dir(EnumSubclass) if and only if __new__ has been overridden outside of enum.py. That's because, unlike with most Python classes, the fact that enum.Enum has a __new__ method or a __format__ method doesn't really tell you very much about enum.Enum's behaviour, due to how magical enums are. But if it's been overridden in a custom Enum subclass, that does tell you that the enum class has special behaviour in some way — the HTTPStatus enum at Lib/http/init.py:6 is a really good example of that. But you're right: the existing code doesn't work as expected, at all:
|
__new__
inEnum.__dir__
#30421Note: 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: