diff --git a/doc/whatsnew/fragments/9814.bugfix b/doc/whatsnew/fragments/9814.bugfix new file mode 100644 index 0000000000..0d635e6bfd --- /dev/null +++ b/doc/whatsnew/fragments/9814.bugfix @@ -0,0 +1,3 @@ +Fix a crash when a subclass extends ``__slots__``. + +Closes #9814 diff --git a/pylint/checkers/classes/class_checker.py b/pylint/checkers/classes/class_checker.py index ffe47ab156..c3e1a081c8 100644 --- a/pylint/checkers/classes/class_checker.py +++ b/pylint/checkers/classes/class_checker.py @@ -1486,7 +1486,11 @@ def _check_slots(self, node: nodes.ClassDef) -> None: if "__slots__" not in node.locals: return - for slots in node.ilookup("__slots__"): + try: + inferred_slots = tuple(node.ilookup("__slots__")) + except astroid.InferenceError: + return + for slots in inferred_slots: # check if __slots__ is a valid type if isinstance(slots, util.UninferableBase): continue diff --git a/tests/functional/s/slots_checks.py b/tests/functional/s/slots_checks.py index 2c22e968ed..ddef0fb94c 100644 --- a/tests/functional/s/slots_checks.py +++ b/tests/functional/s/slots_checks.py @@ -128,3 +128,17 @@ class Parent: class ChildNotAffectedByValueInSlot(Parent): __slots__ = ('first', ) + + +# https://github.com/pylint-dev/pylint/issues/9814 +class SlotsManipulationTest: + __slots__ = ["a", "b", "c"] + + +class TestChild(SlotsManipulationTest): + __slots__ += ["d", "e", "f"] # pylint: disable=undefined-variable + + +t = TestChild() + +print(t.__slots__)