From 9009189c06dd326b7a4f5b9911d0246976f64509 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Thu, 31 Mar 2022 08:49:01 +0200 Subject: [PATCH] Fix crash in ``super-init-not-called`` checker (#6043) Co-authored-by: Pierre Sassoulas Co-authored-by: Jacob Walls --- ChangeLog | 5 +++++ pylint/checkers/classes/class_checker.py | 11 ++++++----- tests/functional/s/super/super_init_not_called.py | 7 +++++++ tests/functional/s/super/super_init_not_called.txt | 1 + 4 files changed, 19 insertions(+), 5 deletions(-) diff --git a/ChangeLog b/ChangeLog index 11b85324e2..82b868c313 100644 --- a/ChangeLog +++ b/ChangeLog @@ -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 diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index f5efc4dc7c..a426b99601 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -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 diff --git a/tests/functional/s/super/super_init_not_called.py b/tests/functional/s/super/super_init_not_called.py index c8e9f09d1e..90a884b0b0 100644 --- a/tests/functional/s/super/super_init_not_called.py +++ b/tests/functional/s/super/super_init_not_called.py @@ -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 diff --git a/tests/functional/s/super/super_init_not_called.txt b/tests/functional/s/super/super_init_not_called.txt index 615b24a542..aafaa2023c 100644 --- a/tests/functional/s/super/super_init_not_called.txt +++ b/tests/functional/s/super/super_init_not_called.txt @@ -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