Repository navigation
Emit assigning-non-slot for @dataclass(slots=True) classes - #11773
Open
Thanatos9404 wants to merge 1 commit into
Open
Thanatos9404 wants to merge 1 commit into
Thanatos9404 wants to merge 1 commit into
Conversation
``@dataclass(slots=True)`` creates ``__slots__`` from the fields at runtime, so the class body has none and the check returned early, although assigning an undeclared attribute raises AttributeError. Take the slots of such a class from its fields and those of its ancestors. Closes pylint-dev#7790
Contributor
|
🤖 Effect of this PR on checked open source code: 🤖 Effect on pandas: Changed messages: Details
This comment was generated for commit 84c463a |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #11773 +/- ##
==========================================
+ Coverage 94.53% 94.54% +0.01%
==========================================
Files 187 187
Lines 21174 21199 +25
Branches 4698 4709 +11
==========================================
+ Hits 20016 20043 +27
+ Misses 690 688 -2
Partials 468 468
🚀 New features to boost your workflow:
|
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Type of Changes
Description
@dataclass(slots=True)creates__slots__from the class's fields at runtime, so the class body has no__slots__and_check_in_slotsreturned early. Assigning an undeclared attribute, as in the issue's example, raisesAttributeErrorat runtime but wasn't reported. The same class written with an explicit__slots__already getsassigning-non-slot, so this reuses that message rather thanno-member.For a class decorated with
@dataclass(slots=True)(or@dataclasses.dataclass(slots=True)), the slots are now its annotated fields,ClassVars excluded, plus the slots of its ancestors. The rest of the check is unchanged:__dict__, so nothing is reported.__setattr__are handled as before.__class__assignments: skipped for these classes, since there is no__slots__layout to compare.Not covered:
slots=<name>or**optionspassed to the decorator;__slots__class that inherits from a slots dataclass, which is still unchecked, as before.The new functional test
assigning_non_slot_dataclassincludes the issue's example. It covers methods and__post_init__, subclasses, and a dataclass on a__slots__base. It also covers the cases that must stay silent: declared fields,slots=False, a plain@dataclass, and an ancestor without slots. Every line it reports raisesAttributeErrorwhen reached. The test fails onmainand passes here, and the changed lines are fully covered, branches included.Closes #7790