Skip to content

Commit d076cc6

Browse files
committed
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 <[email protected]>
1 parent 4430e19 commit d076cc6

File tree

2 files changed

+7
-0
lines changed

2 files changed

+7
-0
lines changed

doc/whatsnew/2/2.15/index.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,8 @@ Extensions
3333
False positives fixed
3434
=====================
3535

36+
* Don't report ``super-init-not-called`` for subclasses of ``Enum`` (on Python >= 3.11).
37+
3638
* Don't report ``unsupported-binary-operation`` on Python <= 3.9 when using the ``|`` operator
3739
with types, if one has a metaclass that overloads ``__or__`` or ``__ror__`` as appropriate.
3840

pylint/checkers/classes/class_checker.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,6 +2059,11 @@ def _check_init(self, node: nodes.FunctionDef, klass_node: nodes.ClassDef) -> No
20592059
except astroid.InferenceError:
20602060
continue
20612061

2062+
# Skip if klass is Enum, Python's own docs and examples
2063+
# do not recommend Enum subclasses call Enum.__init__
2064+
if klass.name == "Enum":
2065+
continue
2066+
20622067
if decorated_with(node, ["typing.overload"]):
20632068
continue
20642069
cls = node_frame_class(method)

0 commit comments

Comments
 (0)