-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Adds docs about new __slots__
feature
#11186
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Left a few ideas about minor tweaks.
Done! @JukkaL and @JelleZijlstra, thanks a lot for the review! |
docs/source/class_basics.rst
Outdated
(the rules are the same as in CPython): | ||
|
||
1. All base classes (except builtin ones) must have explicit ``__slots__`` defined | ||
2. ``__slots__`` must not include ``__dict__``. For example, ``__slots__ = ("__dict__", ...)`` is not valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pretty sure CPython allows __slots__
to include __dict__
.
If dynamic assignment of new variables is desired, then add 'dict' to the sequence of strings in the slots declaration.
So this would fall under custom rules, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It is very debatable whether slotted class with __dict__
is still a slotted class 🤔
Probably it can be in any category.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see where I got confused, suggested some phrasing changes :-)
docs/source/class_basics.rst
Outdated
(the rules are the same as in CPython): | ||
|
||
1. All base classes (except builtin ones) must have explicit ``__slots__`` defined | ||
2. ``__slots__`` must not include ``__dict__``. For example, ``__slots__ = ("__dict__", ...)`` is not valid. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I see where I got confused, suggested some phrasing changes :-)
Co-authored-by: Shantanu <[email protected]>
@hauntsaninja thanks, great suggestion! 👍 |
Thank you for both the feature and the docs! |
Refs #10801
Refs #10864