Skip to content

Don't emit super-init-not-called for Enum subclasses #7181

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

Closed
wants to merge 1 commit into from
Closed
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
2 changes: 2 additions & 0 deletions doc/whatsnew/2/2.15/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ Extensions
False positives fixed
=====================

* Don't report ``super-init-not-called`` for subclasses of ``Enum`` (on Python >= 3.11).

* Don't report ``unsupported-binary-operation`` on Python <= 3.9 when using the ``|`` operator
with types, if one has a metaclass that overloads ``__or__`` or ``__ror__`` as appropriate.

Expand Down
5 changes: 5 additions & 0 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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":
Copy link
Member

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.

Suggested change
if klass.name == "Enum":
if klass.qname() == "enum.Enum":

continue

if decorated_with(node, ["typing.overload"]):
continue
cls = node_frame_class(method)
Expand Down