Skip to content

Commit

Permalink
Fix a crash when a subclass extends __slots__ (#9817) (#9822)
Browse files Browse the repository at this point in the history
(cherry picked from commit 8e18fc0)

Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
  • Loading branch information
jacobtylerwalls and Pierre-Sassoulas authored Jul 20, 2024
1 parent c0b1d22 commit 5f19cd5
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
3 changes: 3 additions & 0 deletions doc/whatsnew/fragments/9814.bugfix
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Fix a crash when a subclass extends ``__slots__``.

Closes #9814
6 changes: 5 additions & 1 deletion pylint/checkers/classes/class_checker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
14 changes: 14 additions & 0 deletions tests/functional/s/slots_checks.py
Original file line number Diff line number Diff line change
Expand Up @@ -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__)

0 comments on commit 5f19cd5

Please sign in to comment.