From d076cc6c92be9e34f8dd35a5cdb21e817d0d00f6 Mon Sep 17 00:00:00 2001 From: Adam Williamson Date: Mon, 11 Jul 2022 15:07:02 -0700 Subject: [PATCH] Don't emit super-init-not-called for Enum subclasses 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 --- doc/whatsnew/2/2.15/index.rst | 2 ++ pylint/checkers/classes/class_checker.py | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/doc/whatsnew/2/2.15/index.rst b/doc/whatsnew/2/2.15/index.rst index 3f3e34ba88..929f232509 100644 --- a/doc/whatsnew/2/2.15/index.rst +++ b/doc/whatsnew/2/2.15/index.rst @@ -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. diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index c345f41b59..561c400380 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -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": + continue + if decorated_with(node, ["typing.overload"]): continue cls = node_frame_class(method)