From 19297979000d049a55124b60c777c7629ee9ac49 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Mon, 15 Apr 2024 19:58:52 +0100 Subject: [PATCH 01/12] gh-115775: Add whatnew entry about __static_attributes__ --- Doc/whatsnew/3.13.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 83c528814c967e..2affa852087f2f 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -115,6 +115,10 @@ Improved Error Messages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'? +* Classes have a new ``__static_attributes__``, populated by the compiler, + with a tuple of names of attributes of this class which are accessed + through ``self.X`` from any function in its body. + Incremental Garbage Collection ------------------------------ From 376d01e915431cf1d99519638106e5daf4dc5ba9 Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Mon, 15 Apr 2024 20:56:45 +0100 Subject: [PATCH 02/12] Update 3.13.rst Co-authored-by: Kirill Podoprigora --- Doc/whatsnew/3.13.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 2affa852087f2f..2c460ba5912dc6 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -115,7 +115,7 @@ Improved Error Messages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'? -* Classes have a new ``__static_attributes__``, populated by the compiler, +* Classes have a new ``__static_attributes__`` attribute, populated by the compiler, with a tuple of names of attributes of this class which are accessed through ``self.X`` from any function in its body. From a8ea23de2e20ad83a09c22e36052ae2d9e46620d Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Tue, 16 Apr 2024 14:52:18 +0100 Subject: [PATCH 03/12] add doc ref --- Doc/reference/datamodel.rst | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 6d6395a21f65d2..85d5387d3bc9be 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1000,6 +1000,10 @@ Special attributes: A tuple containing the :ref:`type parameters ` of a :ref:`generic class `. + :attr:`__static_attributes__` + A tuple containing names of attributes of this class which are accessed + through ``self.X`` from any function in its body. + Class instances --------------- From 2682ce392ad3e520398a68fc7e3324e6f0aa95ee Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Tue, 16 Apr 2024 14:54:42 +0100 Subject: [PATCH 04/12] add contributor --- Doc/whatsnew/3.13.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 2c460ba5912dc6..3704ad8217ea71 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -117,7 +117,8 @@ Improved Error Messages * Classes have a new ``__static_attributes__`` attribute, populated by the compiler, with a tuple of names of attributes of this class which are accessed - through ``self.X`` from any function in its body. + through ``self.X`` from any function in its body. (Contributed by Irit Katriel + in :gh:`115775`.) Incremental Garbage Collection ------------------------------ From f36941417fdafd3958e324b2856b9554cf0687e9 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 18 Apr 2024 00:23:15 +0100 Subject: [PATCH 05/12] add ref --- Doc/reference/datamodel.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 85d5387d3bc9be..6c94a68aa95f01 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -633,6 +633,12 @@ Most of these attributes check the type of the assigned value: .. versionadded:: 3.12 + * - .. attribute:: function.__static_attributes__ + - A :class:`tuple` containing names of attributes of this class which + are accessed through ``self.X`` from any function in its body. + + .. versionadded:: 3.13 + Function objects also support getting and setting arbitrary attributes, which can be used, for example, to attach metadata to functions. Regular attribute dot-notation is used to get and set such attributes. From 27994ff6783bf01d6623f96d5659ac2ce9c3499b Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 18 Apr 2024 00:27:06 +0100 Subject: [PATCH 06/12] add index --- Doc/reference/datamodel.rst | 1 + 1 file changed, 1 insertion(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 6c94a68aa95f01..83a0d01803b823 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -976,6 +976,7 @@ A class object can be called (see above) to yield a class instance (see below). single: __doc__ (class attribute) single: __annotations__ (class attribute) single: __type_params__ (class attribute) + single: __static_attributes__ (class attribute) Special attributes: From a4c1fd0dd894d95cea737694f4016341ab121108 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 18 Apr 2024 10:32:22 +0100 Subject: [PATCH 07/12] class prefix --- Doc/reference/datamodel.rst | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 83a0d01803b823..e7f193e2615b2f 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -627,12 +627,6 @@ Most of these attributes check the type of the assigned value: - A :class:`dictionary ` containing defaults for keyword-only :term:`parameters `. - * - .. attribute:: function.__type_params__ - - A :class:`tuple` containing the :ref:`type parameters ` of - a :ref:`generic function `. - - .. versionadded:: 3.12 - * - .. attribute:: function.__static_attributes__ - A :class:`tuple` containing names of attributes of this class which are accessed through ``self.X`` from any function in its body. @@ -1007,7 +1001,7 @@ Special attributes: A tuple containing the :ref:`type parameters ` of a :ref:`generic class `. - :attr:`__static_attributes__` + :attr:`~class.__static_attributes__` A tuple containing names of attributes of this class which are accessed through ``self.X`` from any function in its body. From 92a3f480e5e9d92f1f3398ed9265d8790dc490ec Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 18 Apr 2024 10:35:50 +0100 Subject: [PATCH 08/12] remove wrong one --- Doc/reference/datamodel.rst | 6 ------ 1 file changed, 6 deletions(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index e7f193e2615b2f..889aff091b3335 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -627,12 +627,6 @@ Most of these attributes check the type of the assigned value: - A :class:`dictionary ` containing defaults for keyword-only :term:`parameters `. - * - .. attribute:: function.__static_attributes__ - - A :class:`tuple` containing names of attributes of this class which - are accessed through ``self.X`` from any function in its body. - - .. versionadded:: 3.13 - Function objects also support getting and setting arbitrary attributes, which can be used, for example, to attach metadata to functions. Regular attribute dot-notation is used to get and set such attributes. From 732e9d28141a3e195edee9a8a7dff8603e0abfa8 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 18 Apr 2024 10:37:40 +0100 Subject: [PATCH 09/12] revert unintended --- Doc/reference/datamodel.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 889aff091b3335..5e1558362ffaa0 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -627,6 +627,12 @@ Most of these attributes check the type of the assigned value: - A :class:`dictionary ` containing defaults for keyword-only :term:`parameters `. + * - .. attribute:: function.__type_params__ + - A :class:`tuple` containing the :ref:`type parameters ` of + a :ref:`generic function `. + + .. versionadded:: 3.12 + Function objects also support getting and setting arbitrary attributes, which can be used, for example, to attach metadata to functions. Regular attribute dot-notation is used to get and set such attributes. From 83675d66931b262735db00784a25b50f4a7cda53 Mon Sep 17 00:00:00 2001 From: Irit Katriel Date: Thu, 18 Apr 2024 10:58:28 +0100 Subject: [PATCH 10/12] class is not right --- Doc/reference/datamodel.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index 5e1558362ffaa0..e4768f3016ff87 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1001,7 +1001,7 @@ Special attributes: A tuple containing the :ref:`type parameters ` of a :ref:`generic class `. - :attr:`~class.__static_attributes__` + :attr:`__static_attributes__` A tuple containing names of attributes of this class which are accessed through ``self.X`` from any function in its body. From eedd5b5f821bd6e6033cce97e35407a2ff63c440 Mon Sep 17 00:00:00 2001 From: Petr Viktorin Date: Thu, 18 Apr 2024 14:11:46 +0200 Subject: [PATCH 11/12] Add to the other list of auto-added class attributes (#57) --- Doc/library/stdtypes.rst | 7 +++++++ Doc/reference/datamodel.rst | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index fc613d4dbe1b5c..a6aaac193a8ba2 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5542,6 +5542,13 @@ types, where they are relevant. Some of these are not reported by the [, , , ] +.. method:: class.__static_attributes__ + + A tuple containing names of attributes of this class which are accessed + through ``self.X`` from any function in its body. + + .. versionadded:: 3.13 + .. _int_max_str_digits: Integer string conversion length limitation diff --git a/Doc/reference/datamodel.rst b/Doc/reference/datamodel.rst index e4768f3016ff87..5e1558362ffaa0 100644 --- a/Doc/reference/datamodel.rst +++ b/Doc/reference/datamodel.rst @@ -1001,7 +1001,7 @@ Special attributes: A tuple containing the :ref:`type parameters ` of a :ref:`generic class `. - :attr:`__static_attributes__` + :attr:`~class.__static_attributes__` A tuple containing names of attributes of this class which are accessed through ``self.X`` from any function in its body. From 275c349e812f67d3b3b3c3d98cf7688f2c1de17a Mon Sep 17 00:00:00 2001 From: Irit Katriel <1055913+iritkatriel@users.noreply.github.com> Date: Fri, 19 Apr 2024 11:35:11 +0100 Subject: [PATCH 12/12] Apply suggestions from code review Co-authored-by: Jelle Zijlstra --- Doc/library/stdtypes.rst | 2 +- Doc/whatsnew/3.13.rst | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/stdtypes.rst b/Doc/library/stdtypes.rst index a6aaac193a8ba2..6c13bd015d5691 100644 --- a/Doc/library/stdtypes.rst +++ b/Doc/library/stdtypes.rst @@ -5542,7 +5542,7 @@ types, where they are relevant. Some of these are not reported by the [, , , ] -.. method:: class.__static_attributes__ +.. attribute:: class.__static_attributes__ A tuple containing names of attributes of this class which are accessed through ``self.X`` from any function in its body. diff --git a/Doc/whatsnew/3.13.rst b/Doc/whatsnew/3.13.rst index 3704ad8217ea71..0e82bc1c01b4d8 100644 --- a/Doc/whatsnew/3.13.rst +++ b/Doc/whatsnew/3.13.rst @@ -115,7 +115,7 @@ Improved Error Messages ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^ TypeError: split() got an unexpected keyword argument 'max_split'. Did you mean 'maxsplit'? -* Classes have a new ``__static_attributes__`` attribute, populated by the compiler, +* Classes have a new :attr:`~class.__static_attributes__` attribute, populated by the compiler, with a tuple of names of attributes of this class which are accessed through ``self.X`` from any function in its body. (Contributed by Irit Katriel in :gh:`115775`.)