Skip to content

fix: preserve slots declared on slotted attrs classes - #1642

Open
DawnofGenX wants to merge 2 commits into
python-attrs:mainfrom
DawnofGenX:fix/slotted-attrs-preserve-own-slots
Open

DawnofGenX wants to merge 2 commits into
python-attrs:mainfrom
DawnofGenX:fix/slotted-attrs-preserve-own-slots

Conversation

@DawnofGenX

Copy link
Copy Markdown

Problem

Slots declared on a slotted attrs class are lost:

@attrs.define
class A:
    __slots__ = ("private",)
    public: str = "foo"

a = A()
a.private = 1  # TypeError

Fix

Preserve slots declared on the slotted attrs class itself, not just inherited slots.

Verification

  • New test fails on main, passes with fix.
  • Full test suite passes.

Iterate the already-filtered list of the class's own slots instead of
re-testing each own slot against the combined slot_names in the descriptor
cleanup loop. The popped set is unchanged (a name is only in own_new_slots
when it is added to slot_names), but the redundant membership test
introduced a branch that is never taken for valid input, which the 100%
branch-coverage gate rejects.

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant