Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 34k
gh-103740: Improve support of __slots__ for variable-length classes#141636
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
gh-103740: Improve support of __slots__ for variable-length classes #141636
Uh oh!
There was an error while loading. Please reload this page.
Conversation
serhiy-storchaka commented Nov 16, 2025 • edited by github-actions bot
Loading Uh oh!
There was an error while loading. Please reload this page.
edited by github-actions bot
Uh oh!
There was an error while loading. Please reload this page.
…sses * Allow defining the __dict__ and __weakref__ __slots__ for any class. * Allow defining any __slots__ for a class derived from the type class or other "variable-length" built-in type with the Py_TPFLAGS_ITEMS_AT_END flag.
8c3d950 to c17b254CompareUh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
picnixz commented Nov 17, 2025
Well.. that's weird. The docs still fail? |
Misc/NEWS.d/next/Core_and_Builtins/2025-11-16-21-14-48.gh-issue-103740.rXIj5h.rst Outdated Show resolvedHide resolved
Uh oh!
There was an error while loading. Please reload this page.
…e-103740.rXIj5h.rst Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
serhiy-storchaka commented Nov 17, 2025
Thank you. I noticed this error yesterday (this is is the second time I make such error in a month), but it was already late night. |
picnixz commented Nov 17, 2025
No worry! don't hesitate to ping in the future if you encounter other Sphinx errors! |
encukou left a comment
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.
Thank you!
I need a bit more time to review the code; sending docs suggestions in the meantime.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Co-authored-by: Petr Viktorin <encukou@gmail.com>
| For example, *__slots__* other than *__dict__* and *__weakref__* cannot | ||
| be defined on subclasses of :class:`int`, :class:`bytes`, or :class:`tuple`. |
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.
Maybe use "they"?
| For example, *__slots__* other than *__dict__* and *__weakref__* cannot | |
| be defined on subclasses of :class:`int`, :class:`bytes`, or :class:`tuple`. | |
| For example, they cannot be defined on subclasses of | |
| :class:`int`, :class:`bytes`, or :class:`tuple`. |
encukou commented Nov 18, 2025 • edited
Loading Uh oh!
There was an error while loading. Please reload this page.
edited
Uh oh!
There was an error while loading. Please reload this page.
The only >>>classMeta(type): ... __slots__= ['foo'] # now possible ... >>>classX(metaclass=Meta): ... deffoo(self): return'f' ... >>>X().foo<boundmethodX.fooof<__main__.Xobjectat0x7f7c579c2900>>>>>X.fooTraceback (mostrecentcalllast): File"<python-input-3>", line1, in<module>X.fooAttributeError: 'Meta'objecthasnoattribute'foo'>>>X.foo=slice>>>X.foo(X()) slice(None, <__main__.Xobjectat0x7f7c5788c050>, None) >>>X().foo() 'f'Do we want to make this easier? |
serhiy-storchaka commented Nov 18, 2025
I did not have any use case for this feature, but this looks interesting. We already have data descriptors ( classMeta(type): @propertydeffoo(self): returnsliceclassX(metaclass=Meta): deffoo(self): return'f'print(X.foo(X())) print(X().foo()) |
encukou commented Nov 19, 2025
Yes, descriptors are already weird. But given stdlib's non-usage of What about explicitly disabling arbitrary The |
serhiy-storchaka commented Nov 19, 2025
Was not it the same with PEP 697? It allowed extending Anyway, I am only interesting in extending tuples. Adding support for special slots would be a side effect. Supporting |
serhiy-storchaka commented Nov 19, 2025
See #141755. |
encukou commented Nov 19, 2025
PEP 697's “extending” was about adding a C-level chunk of memory, not about Python attributes. You can already extend Having a |
serhiy-storchaka commented Nov 19, 2025
The other half of this PR (very simple) has been moved to #141764. |
serhiy-storchaka commented Nov 19, 2025
Lets discuss this not in PRs, but in the issue #103740. |
📚 Documentation preview 📚: https://cpython-previews--141636.org.readthedocs.build/