Skip to content
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

Fix crash in super-init-not-called checker #6043

Merged
merged 7 commits into from
Mar 31, 2022
Merged
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
5 changes: 5 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,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():
jacobtylerwalls marked this conversation as resolved.
Show resolved Hide resolved
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