From 605ea6644c050fc23384335ceb9d8f259071a338 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Tue, 14 Feb 2023 16:23:15 -0800 Subject: [PATCH] PEP 688: Expand backwards compatibility section (#3007) Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Hugo van Kemenade --- pep-0688.rst | 37 ++++++++++++++++++++++++++++++++++--- 1 file changed, 34 insertions(+), 3 deletions(-) diff --git a/pep-0688.rst b/pep-0688.rst index 38c3fc05a..bd7eca7f2 100644 --- a/pep-0688.rst +++ b/pep-0688.rst @@ -293,10 +293,41 @@ should deprecate and eventually remove it. Backwards Compatibility ======================= -As the runtime changes in this PEP only add new functionality, there are -no backwards compatibility concerns. +``__buffer__`` and ``__release_buffer__`` attributes +---------------------------------------------------- -However, the recommendation to remove the special behavior for +As the runtime changes in this PEP only add new functionality, there are +few backwards compatibility concerns. + +However, code that uses a ``__buffer__`` or ``__release_buffer__`` attribute for +other purposes may be affected. While all dunders are technically reserved for the +language, it is still good practice to ensure that a new dunder does not +interfere with too much existing code, especially widely used packages. A survey +of publicly accessible code found: + +- PyPy `supports `__ + a ``__buffer__`` method with compatible semantics to those proposed in this + PEP. A PyPy core developer `expressed his support `__ + for this PEP. +- pyzmq `implements `__ + a PyPy-compatible ``__buffer__`` method. +- mpi4py `defines `__ + a ``SupportsBuffer`` protocol that would be equivalent to this PEP's ``collections.abc.Buffer``. +- NumPy used to have an undocumented behavior where it would access a ``__buffer__`` attribute + (not method) to get an object's buffer. This was `removed `__ + in 2019 for NumPy 1.17. The behavior would have last worked in NumPy 1.16, which only supported + Python 3.7 and older. Python 3.7 will have reached its end of life by the time this PEP is expected to + be implemented. + +Thus, this PEP's use of the ``__buffer__`` method will improve interoperability with +PyPy and not interfere with the current versions of any major Python packages. + +No publicly accessible code uses the name ``__release_buffer__``. + +Removal of the ``bytes`` special case +------------------------------------- + +Separately, the recommendation to remove the special behavior for ``bytes`` in type checkers does have a backwards compatibility impact on their users. An `experiment `__ with mypy shows that several major open source projects that use it