Skip to content

Commit

Permalink
Fix crash in super-init-not-called checker (#6043)
Browse files Browse the repository at this point in the history
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Co-authored-by: Jacob Walls <jacobtylerwalls@gmail.com>
  • Loading branch information
3 people committed Mar 31, 2022
1 parent 8812626 commit 9009189
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 5 deletions.
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,11 @@ Release date: TBA

Closes #6028

* Fix crash in ``super-init-not-called`` checker when using ``ctypes.Union``.

Closes #6027


* Fix crash for ``unneccessary-ellipsis`` checker when an ellipsis is used inside of a container or a lambda expression.

Closes #6036
Expand Down
11 changes: 6 additions & 5 deletions pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -1999,11 +1999,12 @@ def _check_init(self, node: nodes.FunctionDef, klass_node: nodes.ClassDef) -> No

# Return if any of the klass' first-order bases is protocol
for base in klass.bases:
# We don't need to catch InferenceError here as _ancestors_to_call
# already does this for us.
for inf_base in base.infer():
if inf_base.qname() in utils.TYPING_PROTOCOLS:
return
try:
for inf_base in base.infer():
if inf_base.qname() in utils.TYPING_PROTOCOLS:
return
except astroid.InferenceError:
continue

if decorated_with(node, ["typing.overload"]):
continue
Expand Down
7 changes: 7 additions & 0 deletions tests/functional/s/super/super_init_not_called.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,3 +48,10 @@ def __init__(self):
class ChildThree(ParentWithoutInit):
def __init__(self): # [super-init-not-called]
...


# Regression test as reported in
# https://github.com/PyCQA/pylint/issues/6027
class MyUnion(ctypes.Union):
def __init__(self): # [super-init-not-called]
pass
1 change: 1 addition & 0 deletions tests/functional/s/super/super_init_not_called.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
undefined-variable:18:23:18:40:UninferableChild:Undefined variable 'UninferableParent':UNDEFINED
super-init-not-called:49:4:49:16:ChildThree.__init__:__init__ method from base class 'ParentWithoutInit' is not called:INFERENCE
super-init-not-called:56:4:56:16:MyUnion.__init__:__init__ method from base class 'Union' is not called:INFERENCE

0 comments on commit 9009189

Please sign in to comment.