From e9456773643c7dcca584ae0100db42639b93f04e Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 7 Feb 2022 16:09:57 +0100 Subject: [PATCH] PEP 674: Address Petr's review --- pep-0674.rst | 84 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 49 insertions(+), 35 deletions(-) diff --git a/pep-0674.rst b/pep-0674.rst index 7568a877d98..ecf14445eb6 100644 --- a/pep-0674.rst +++ b/pep-0674.rst @@ -1,5 +1,5 @@ PEP: 674 -Title: Disallow using Py_TYPE() and Py_SIZE() macros as l-values +Title: Disallow using macros as l-values Author: Victor Stinner Status: Draft Type: Standards Track @@ -10,16 +10,8 @@ Python-Version: 3.11 Abstract ======== -Incompatible C API change disallowing using macros, especially -``Py_TYPE()`` and ``Py_SIZE()``, as l-values to: - -* Allow evolving CPython internals (change the ``PyObject`` structure); -* Ease the C API implementation on other Python implementation; -* Help migrating existing C extensions to the HPy API. - -Only 7 out of the top 5000 PyPI projects (0.1%) are affected by this -PEP. An additional 23 projects just have to regenerate their Cython -code. +Disallow using macros as l-values. For example, +``Py_TYPE(obj) = new_type`` now fails with a compiler error. In practice, the majority of affected projects only have to make two changes: @@ -301,6 +293,9 @@ Backwards Compatibility The proposed C API changes are backward incompatible on purpose. +In practice, only ``Py_TYPE()`` and ``Py_SIZE()`` macros are used as +l-values. + This change does not follow the :pep:`387` deprecation process. There is no known way to emit a deprecation warning only when a macro is used as an l-value, but not when it's used differently (ex: as a r-value). @@ -309,46 +304,44 @@ The following 4 macros are left unchanged to reduce the number of affected projects: ``PyDescr_NAME()``, ``PyDescr_TYPE()``, ``PyList_GET_ITEM()`` and ``PyTuple_GET_ITEM()``. +Statistics +---------- + +In total (projects on PyPI and not on PyPI), 41 projects are affected by +this PEP: + +* 14 projects (34%) are already fixed +* 27 projects (66%) are not fixed yet + (pending fix or generated Cython code) + +On January 27, 2022, the PEP affects 27 projects (0.5%) of the top 5000 +PyPI projects: + +* 22 projects (0.4%) have to regenerate their Cython code +* 5 projects (0.1%) have a pending fix + Top 5000 PyPI ------------- -On January 27, 2022, a code search on the top 5000 PyPI projects found -that only 7 projects are affected (0.1%): +Projects with a pending fix (5): * datatable (1.0.0): `pending PR `__ -* guppy3 (3.1.2): `fixed `__ -* pickle5 (0.0.12): backport for Python <= 3.7 -* pysha3 (1.0.2): backport for Python <= 3.5 +* guppy3 (3.1.2): + `fixed `__ * python-snappy (0.6.0): `fixed `__ * recordclass (0.17.1): `fixed `__ * scipy (1.7.3): fixed (need to update boost) -All of those projects are fixed (but not released), have a pending fix, -or should not be fixed (backports). - -An additional 23 projects only have to regenerate their Cython code to -use ``Py_SET_TYPE()`` and ``Py_SET_SIZE()``. - -Only 2 macros are used as an l-value: ``Py_TYPE()`` and ``Py_SIZE()``. +Moreover, 22 projects have to regenerate their Cython code. -Projects released with a fix ----------------------------- - -Projects released with a fix (14): +Projects released with a fix (10): * bitarray (1.6.2): `commit `__ -* boost (1.78.0): `commit - `__ -* breezy (3.2.1): `bug report `__ * Cython (0.29.20): `commit `__ -* duplicity (0.8.18): - `commit `__ -* gobject-introspection (1.70.0): - `MR `__ * immutables (0.15): `commit `__ * mercurial (5.7): @@ -364,9 +357,30 @@ Projects released with a fix (14): * PyGObject (3.42.0) * pyside2 (5.15.1): `bug report `__ -* python-zstd (1.5.0.3): +* zstd (1.5.0.3): `commit `__ +There are also two backport projects which are affected by this PEP: + +* pickle5 (0.0.12): backport for Python <= 3.7 +* pysha3 (1.0.2): backport for Python <= 3.5 + +They must not be used and cannot be used on Python 3.11. + +Other affected projects +----------------------- + +Other projects released with a fix (4): + +* boost (1.78.0): + `commit `__ +* breezy (3.2.1): + `bug report `__ +* duplicity (0.8.18): + `commit `__ +* gobject-introspection (1.70.0): + `MR `__ + Relationship with the HPy project =================================