Skip to content

Preserve user defined slots on attrs classes... - #1644

Open
emadleo13 wants to merge 3 commits into
python-attrs:mainfrom
emadleo13:fix-1637-user-defined-slots
Open

emadleo13 wants to merge 3 commits into
python-attrs:mainfrom
emadleo13:fix-1637-user-defined-slots

Conversation

@emadleo13

Copy link
Copy Markdown

Summary

When an attrs class defines __slots__ explicitly, the generated slotted class did not preserve those user-defined slots.

This change preserves explicitly declared __slots__ while avoiding duplicate slots inherited from base classes.

Changes

  • Preserve user-defined __slots__ when generating the slotted class.
  • Support both tuple-based and string-based __slots__.
  • Avoid re-creating slots already inherited from base classes.
  • Remove the original slot descriptors from the class dictionary before creating the new class.

Tests

Added regression tests covering:

  • User-defined tuple-based slots.
  • User-defined string-based slots.
  • User-defined slots combined with inherited slots.

Full test suite:

  • 1410 passed
  • 4 skipped
  • 2 x failed

@emadleo13
emadleo13 force-pushed the fix-1637-user-defined-slots branch from 9e235d9 to 1e0115e Compare October 17, 2026 21:47

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