From 6f2a997cbb365215ae172e46373d8489bdcb8fa0 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 2 Jul 2021 23:04:36 +0200 Subject: [PATCH 01/15] bpo-43908: Let Py_TPFLAGS_IMMUTABLETYPE decide if Py_TPFLAGS_HAVE_VECTORCALL can be inherited --- Objects/typeobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index 116ac14cbc2a64..a8af663a51c70a 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5881,8 +5881,8 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base) /* Inherit Py_TPFLAGS_HAVE_VECTORCALL for non-heap types * if tp_call is not overridden */ if (!type->tp_call && - (base->tp_flags & Py_TPFLAGS_HAVE_VECTORCALL) && - !(type->tp_flags & Py_TPFLAGS_HEAPTYPE)) + _PyType_HasFeature(base, Py_TPFLAGS_HAVE_VECTORCALL) && + _PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE)) { type->tp_flags |= Py_TPFLAGS_HAVE_VECTORCALL; } From c1db2cebf6528f5a335897c7d353197014560d2b Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 2 Jul 2021 23:23:53 +0200 Subject: [PATCH 02/15] Adjust test_call comments --- Lib/test/test_call.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Lib/test/test_call.py b/Lib/test/test_call.py index 3f459222748b3a..c929ca87ddcd56 100644 --- a/Lib/test/test_call.py +++ b/Lib/test/test_call.py @@ -563,7 +563,7 @@ def test_method_descriptor_flag(self): self.assertTrue(_testcapi.MethodDescriptorDerived.__flags__ & Py_TPFLAGS_METHOD_DESCRIPTOR) self.assertFalse(_testcapi.MethodDescriptorNopGet.__flags__ & Py_TPFLAGS_METHOD_DESCRIPTOR) - # Heap type should not inherit Py_TPFLAGS_METHOD_DESCRIPTOR + # Mutable heap types should not inherit Py_TPFLAGS_METHOD_DESCRIPTOR class MethodDescriptorHeap(_testcapi.MethodDescriptorBase): pass self.assertFalse(MethodDescriptorHeap.__flags__ & Py_TPFLAGS_METHOD_DESCRIPTOR) @@ -574,7 +574,7 @@ def test_vectorcall_flag(self): self.assertFalse(_testcapi.MethodDescriptorNopGet.__flags__ & Py_TPFLAGS_HAVE_VECTORCALL) self.assertTrue(_testcapi.MethodDescriptor2.__flags__ & Py_TPFLAGS_HAVE_VECTORCALL) - # Heap type should not inherit Py_TPFLAGS_HAVE_VECTORCALL + # Mutable heap types should not inherit Py_TPFLAGS_HAVE_VECTORCALL class MethodDescriptorHeap(_testcapi.MethodDescriptorBase): pass self.assertFalse(MethodDescriptorHeap.__flags__ & Py_TPFLAGS_HAVE_VECTORCALL) From dd42fdf14bd801663fb15400e52e1b84c835e758 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Fri, 2 Jul 2021 23:24:23 +0200 Subject: [PATCH 03/15] Py_TPFLAGS_METHOD_DESCRIPTOR is inherited if Py_TPFLAGS_IMMUTABLETYPE is set --- Objects/typeobject.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Objects/typeobject.c b/Objects/typeobject.c index a8af663a51c70a..02ea618670d8f9 100644 --- a/Objects/typeobject.c +++ b/Objects/typeobject.c @@ -5915,8 +5915,8 @@ inherit_slots(PyTypeObject *type, PyTypeObject *base) * but only for extension types */ if (base->tp_descr_get && type->tp_descr_get == base->tp_descr_get && - !(type->tp_flags & Py_TPFLAGS_HEAPTYPE) && - (base->tp_flags & Py_TPFLAGS_METHOD_DESCRIPTOR)) + _PyType_HasFeature(type, Py_TPFLAGS_IMMUTABLETYPE) && + _PyType_HasFeature(base, Py_TPFLAGS_METHOD_DESCRIPTOR)) { type->tp_flags |= Py_TPFLAGS_METHOD_DESCRIPTOR; } From f3aedd3e20150ff711060fb46f27c0fe2c91fc0a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 3 Jul 2021 00:11:17 +0200 Subject: [PATCH 04/15] Update docs --- Doc/c-api/typeobj.rst | 17 +++++++++-------- 1 file changed, 9 insertions(+), 8 deletions(-) diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index ea811158fa8739..004cecddfdb0d4 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -710,7 +710,7 @@ and :c:type:`PyType_Type` effectively act as defaults.) .. warning:: - It is not recommended for :ref:`heap types ` to implement + It is not recommended for :ref:`mutable heap types ` to implement the vectorcall protocol. When a user sets :attr:`__call__` in Python code, only *tp_call* is updated, likely making it inconsistent with the vectorcall function. @@ -734,8 +734,9 @@ and :c:type:`PyType_Type` effectively act as defaults.) always inherited. If it's not, then the subclass won't use :ref:`vectorcall `, except when :c:func:`PyVectorcall_Call` is explicitly called. - This is in particular the case for :ref:`heap types ` - (including subclasses defined in Python). + This is in particular the case for types without the + :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set (including subclasses defined in + Python). .. c:member:: getattrfunc PyTypeObject.tp_getattr @@ -1125,9 +1126,9 @@ and :c:type:`PyType_Type` effectively act as defaults.) **Inheritance:** - This flag is never inherited by :ref:`heap types `. - For extension types, it is inherited whenever - :c:member:`~PyTypeObject.tp_descr_get` is inherited. + This flag is never inherited by types without the + :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set. For extension types, it is + inherited whenever :c:member:`~PyTypeObject.tp_descr_get` is inherited. .. XXX Document more flags here? @@ -1172,9 +1173,9 @@ and :c:type:`PyType_Type` effectively act as defaults.) **Inheritance:** - This bit is inherited for :ref:`static subtypes ` if + This bit is inherited for types with the + :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set, if :c:member:`~PyTypeObject.tp_call` is also inherited. - :ref:`Heap types ` do not inherit ``Py_TPFLAGS_HAVE_VECTORCALL``. .. versionadded:: 3.9 From 0e421aba1d69f12837602a627ac66121e2efb1cf Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 3 Jul 2021 00:17:50 +0200 Subject: [PATCH 05/15] Add a note in Porting to 3.11 --- Doc/whatsnew/3.11.rst | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 5b51273ed6b9a2..ef2ceae0a76990 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -211,6 +211,12 @@ Porting to Python 3.11 (:c:member:`PyTypeObject.tp_traverse`). (Contributed by Victor Stinner in :issue:`44263`.) +* The :const:`Py_TPFLAGS_HAVE_VECTORCALL` and + :const:`Py_TPFLAGS_METHOD_DESCRIPTOR` flags can now be inherited if the + target type has the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set. Previously, + only :ref:`static types ` could inherit these flags. + (Contributed by Erlend E. Aasland in :issue:`43908`) + Deprecated ---------- From a99cd5c121b0565c4d7b7d5f2ba7a0c4aecfe179 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 3 Jul 2021 00:20:45 +0200 Subject: [PATCH 06/15] Add NEWS --- .../2021-07-03-00-20-39.bpo-43908.YHuV_s.rst | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst new file mode 100644 index 00000000000000..6af4e6c3346d5b --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst @@ -0,0 +1,5 @@ +The :const:`Py_TPFLAGS_HAVE_VECTORCALL` and +:const:`Py_TPFLAGS_METHOD_DESCRIPTOR` flags can now be inherited if the +target type has the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set. Previously, +only :ref:`static types ` could inherit these flags. Patch by +Erlend E. Aasland. From e9ee79c8be420a9005378cd2d697d171907f13f9 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 3 Jul 2021 00:32:23 +0200 Subject: [PATCH 07/15] Simplify What's New/NEWS wording --- Doc/whatsnew/3.11.rst | 7 +++---- .../2021-07-03-00-20-39.bpo-43908.YHuV_s.rst | 8 +++----- 2 files changed, 6 insertions(+), 9 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index ef2ceae0a76990..8e3ec6e578591a 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -211,10 +211,9 @@ Porting to Python 3.11 (:c:member:`PyTypeObject.tp_traverse`). (Contributed by Victor Stinner in :issue:`44263`.) -* The :const:`Py_TPFLAGS_HAVE_VECTORCALL` and - :const:`Py_TPFLAGS_METHOD_DESCRIPTOR` flags can now be inherited if the - target type has the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set. Previously, - only :ref:`static types ` could inherit these flags. +* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set can now implement + the :pep:`590` vectorcall protocol. Previously, this was only available for + :ref:`static types `. (Contributed by Erlend E. Aasland in :issue:`43908`) Deprecated diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst index 6af4e6c3346d5b..2c0c408ed1a704 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst @@ -1,5 +1,3 @@ -The :const:`Py_TPFLAGS_HAVE_VECTORCALL` and -:const:`Py_TPFLAGS_METHOD_DESCRIPTOR` flags can now be inherited if the -target type has the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set. Previously, -only :ref:`static types ` could inherit these flags. Patch by -Erlend E. Aasland. +Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set can now implement +the :pep:`590` vectorcall protocol. Previously, this was only available for +:ref:`static types `. Patch by Erlend E. Aasland. From 593a19f58b5626677ce94e9909bd34e496198562 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Sat, 3 Jul 2021 00:33:59 +0200 Subject: [PATCH 08/15] Fix whitespace --- Doc/whatsnew/3.11.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 8e3ec6e578591a..4d64f48f294c4f 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -214,7 +214,7 @@ Porting to Python 3.11 * Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set can now implement the :pep:`590` vectorcall protocol. Previously, this was only available for :ref:`static types `. - (Contributed by Erlend E. Aasland in :issue:`43908`) + (Contributed by Erlend E. Aasland in :issue:`43908`) Deprecated ---------- From 6adc9e5c8b68000bb3f66f5082401efb7b8a1271 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 6 Jul 2021 13:37:12 +0200 Subject: [PATCH 09/15] Move What's New entry from 3.11 to 3.10 --- Doc/whatsnew/3.10.rst | 5 +++++ Doc/whatsnew/3.11.rst | 5 ----- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index cd3db5550a6bf4..2ce49dcec6d285 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2073,6 +2073,11 @@ Porting to Python 3.10 limited API. The function is mainly useful for custom builds of Python. (Contributed by Petr Viktorin in :issue:`26241`) +* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now implement the + :pep:`590` vectorcall protocol. Previously, this was only available for + :ref:`static types `. + (Contributed by Erlend E. Aasland in :issue:`43908`) + Deprecated ---------- diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 4d64f48f294c4f..5b51273ed6b9a2 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -211,11 +211,6 @@ Porting to Python 3.11 (:c:member:`PyTypeObject.tp_traverse`). (Contributed by Victor Stinner in :issue:`44263`.) -* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set can now implement - the :pep:`590` vectorcall protocol. Previously, this was only available for - :ref:`static types `. - (Contributed by Erlend E. Aasland in :issue:`43908`) - Deprecated ---------- From c9cdfa6a264893b3b44b093f05de60100d0c9361 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 6 Jul 2021 17:38:35 +0200 Subject: [PATCH 10/15] Revert "Move What's New entry from 3.11 to 3.10" This reverts commit 6adc9e5c8b68000bb3f66f5082401efb7b8a1271. --- Doc/whatsnew/3.10.rst | 5 ----- Doc/whatsnew/3.11.rst | 5 +++++ 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst index 2ce49dcec6d285..cd3db5550a6bf4 100644 --- a/Doc/whatsnew/3.10.rst +++ b/Doc/whatsnew/3.10.rst @@ -2073,11 +2073,6 @@ Porting to Python 3.10 limited API. The function is mainly useful for custom builds of Python. (Contributed by Petr Viktorin in :issue:`26241`) -* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now implement the - :pep:`590` vectorcall protocol. Previously, this was only available for - :ref:`static types `. - (Contributed by Erlend E. Aasland in :issue:`43908`) - Deprecated ---------- diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 5b51273ed6b9a2..4d64f48f294c4f 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -211,6 +211,11 @@ Porting to Python 3.11 (:c:member:`PyTypeObject.tp_traverse`). (Contributed by Victor Stinner in :issue:`44263`.) +* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set can now implement + the :pep:`590` vectorcall protocol. Previously, this was only available for + :ref:`static types `. + (Contributed by Erlend E. Aasland in :issue:`43908`) + Deprecated ---------- From 634d1d9625a5aa4704511a2c8b01c9aabe1895c9 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 6 Jul 2021 17:39:21 +0200 Subject: [PATCH 11/15] Minor adjustment of What's New wording --- Doc/whatsnew/3.11.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 4d64f48f294c4f..9bd724e5c6a929 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -211,8 +211,8 @@ Porting to Python 3.11 (:c:member:`PyTypeObject.tp_traverse`). (Contributed by Victor Stinner in :issue:`44263`.) -* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set can now implement - the :pep:`590` vectorcall protocol. Previously, this was only available for +* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now implement the + :pep:`590` vectorcall protocol. Previously, this was only available for :ref:`static types `. (Contributed by Erlend E. Aasland in :issue:`43908`) From 1b035eb0a748cf4560b9cd10c6ae4aa18a56621a Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Tue, 6 Jul 2021 23:52:20 +0200 Subject: [PATCH 12/15] Address review: reword NEWS entry --- .../2021-07-03-00-20-39.bpo-43908.YHuV_s.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst index 2c0c408ed1a704..02855a13f11cb5 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst @@ -1,3 +1,3 @@ -Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag set can now implement -the :pep:`590` vectorcall protocol. Previously, this was only available for +Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now inherit the +:pep:`590` vectorcall protocol. Previously, this was only possible for :ref:`static types `. Patch by Erlend E. Aasland. From b6ed6bd1aad65a6a0323a85bd5d18d29aae1ea85 Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 7 Jul 2021 00:00:10 +0200 Subject: [PATCH 13/15] Also adjust What's New entry --- Doc/whatsnew/3.11.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 9bd724e5c6a929..376a4edc92e8a9 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -211,8 +211,8 @@ Porting to Python 3.11 (:c:member:`PyTypeObject.tp_traverse`). (Contributed by Victor Stinner in :issue:`44263`.) -* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now implement the - :pep:`590` vectorcall protocol. Previously, this was only available for +* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now inherit the + :pep:`590` vectorcall protocol. Previously, this was only possible for :ref:`static types `. (Contributed by Erlend E. Aasland in :issue:`43908`) From fd33dcc91e34f366bd426f5eb33c039a4bd2e678 Mon Sep 17 00:00:00 2001 From: Erlend Egeberg Aasland Date: Wed, 7 Jul 2021 20:54:26 +0200 Subject: [PATCH 14/15] Address review: change wording in NEWS entry (specify heap types) Co-authored-by: Victor Stinner --- .../Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst index 02855a13f11cb5..6113d0f912a5ac 100644 --- a/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst +++ b/Misc/NEWS.d/next/Core and Builtins/2021-07-03-00-20-39.bpo-43908.YHuV_s.rst @@ -1,3 +1,3 @@ -Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now inherit the +Heap types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now inherit the :pep:`590` vectorcall protocol. Previously, this was only possible for :ref:`static types `. Patch by Erlend E. Aasland. From 49362db92504d840097645387ee03e696f4fb3de Mon Sep 17 00:00:00 2001 From: "Erlend E. Aasland" Date: Wed, 7 Jul 2021 20:56:48 +0200 Subject: [PATCH 15/15] Also adjust What's New entry --- Doc/whatsnew/3.11.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.11.rst b/Doc/whatsnew/3.11.rst index 376a4edc92e8a9..952b4192f4c000 100644 --- a/Doc/whatsnew/3.11.rst +++ b/Doc/whatsnew/3.11.rst @@ -211,8 +211,8 @@ Porting to Python 3.11 (:c:member:`PyTypeObject.tp_traverse`). (Contributed by Victor Stinner in :issue:`44263`.) -* Types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now inherit the - :pep:`590` vectorcall protocol. Previously, this was only possible for +* Heap types with the :const:`Py_TPFLAGS_IMMUTABLETYPE` flag can now inherit + the :pep:`590` vectorcall protocol. Previously, this was only possible for :ref:`static types `. (Contributed by Erlend E. Aasland in :issue:`43908`) pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy