-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Don't emit super-init-not-called for Enum subclasses #7181
Conversation
This is split out from #7167 , as requested by @DanielNoord . |
Uh, I guess that line needs to be changed on main so the bot doesn't add it to every single PR? |
Pull Request Test Coverage Report for Build 2665599035
💛 - Coveralls |
Thanks for noticing that's my bad. |
This comment has been minimized.
This comment has been minimized.
For some reason, commit 83d544b to cpython added a `__init__` to `Enum` which does nothing (it just says `pass`). The examples in the Enum docs: https://docs.python.org/3.11/howto/enum.html still do not include calling super's `__init__` for Enum subclasses, that define their own `__init__`, and obviously there is no practical point to calling a method that does nothing, so it seems best just to skip this warning for Enum. Signed-off-by: Adam Williamson <[email protected]>
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit d076cc6 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
@Pierre-Sassoulas can we remove the blocked label here? This doesn't depend on 3.11 support, IMO.
@@ -2059,6 +2059,11 @@ def _check_init(self, node: nodes.FunctionDef, klass_node: nodes.ClassDef) -> No | |||
except astroid.InferenceError: | |||
continue | |||
|
|||
# Skip if klass is Enum, Python's own docs and examples | |||
# do not recommend Enum subclasses call Enum.__init__ | |||
if klass.name == "Enum": |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think elsewhere we check the qname to avoid getting red herrings from other modules.
if klass.name == "Enum": | |
if klass.qname() == "enum.Enum": |
It was blocked by python/cpython#30582 (comment) I think |
@DanielNoord suggests that #7227 would likely avoid the need for this. |
A functional test to make sure of that would be nice :) |
Going to close this as we actually have various regression tests against this throughout our code. Thanks for the initial investigation @AdamWill! |
No problem. Sorry I didn't get around to writing any tests, have had too many piles of things on fire to deal with :| |
Type of Changes
Description
For some reason, commit 83d544b to cpython added a
__init__
to
Enum
which does nothing (it just sayspass
). The examplesin the Enum docs:
https://docs.python.org/3.11/howto/enum.html
still do not include calling super's
__init__
for Enumsubclasses, that define their own
__init__
, and obviously thereis no practical point to calling a method that does nothing, so
it seems best just to skip this warning for Enum.
Signed-off-by: Adam Williamson [email protected]
Blocked by python/cpython#30582 (comment)