From 6f6ba2740c2cf6eea37d297f6fae0bb523aee264 Mon Sep 17 00:00:00 2001 From: TN Date: Sun, 12 Mar 2023 20:57:53 +0800 Subject: [PATCH 1/2] gh-100315: clarification to `__slots__` docs. refer to tp_itemsize in discussion on "variable-length" built-in types --- Doc/reference/datamodel.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index f447bbb1216d52..1030018b8bef7a 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1945,7 +1945,8 @@ Notes on using *__slots__* program undefined. In the future, a check may be added to prevent this. * Nonempty *__slots__* does not work for classes derived from "variable-length" - built-in types such as :class:`int`, :class:`bytes` and :class:`tuple`. + built-in types such as :class:`int`, :class:`bytes` and :class:`tuple` + (see :c:member:`~PyTypeObject.tp_itemsize`). * Any non-string :term:`iterable` may be assigned to *__slots__*. From 3aca8b50826a3b99885182213ffd9074dd6a3b55 Mon Sep 17 00:00:00 2001 From: TN Date: Tue, 14 Mar 2023 10:28:16 +0800 Subject: [PATCH 2/2] reword --- Doc/reference/datamodel.rst | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 1030018b8bef7a..1865d09fcaa127 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1944,9 +1944,10 @@ Notes on using *__slots__* descriptor directly from the base class). This renders the meaning of the program undefined. In the future, a check may be added to prevent this. -* Nonempty *__slots__* does not work for classes derived from "variable-length" - built-in types such as :class:`int`, :class:`bytes` and :class:`tuple` - (see :c:member:`~PyTypeObject.tp_itemsize`). +* :exc:`TypeError` will be raised if nonempty *__slots__* are defined for a + class derived from a + :c:member:`"variable-length" built-in type ` such as + :class:`int`, :class:`bytes`, and :class:`tuple`. * Any non-string :term:`iterable` may be assigned to *__slots__*.