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

[Backport maintenance/3.2.x] Fix a crash when a subclass extends __slots__ (#9817) #9822

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
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__)
Loading