PEP 688: Expand backwards compatibility section (#3007)
Co-authored-by: Shantanu <12621235+hauntsaninja@users.noreply.github.com> Co-authored-by: Hugo van Kemenade <hugovk@users.noreply.github.com>
This commit is contained in:
parent
2b670aa514
commit
605ea6644c
37
pep-0688.rst
37
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 <https://doc.pypy.org/en/latest/__pypy__-module.html#generally-available-functionality>`__
|
||||
a ``__buffer__`` method with compatible semantics to those proposed in this
|
||||
PEP. A PyPy core developer `expressed his support <https://discuss.python.org/t/pep-688-making-the-buffer-protocol-accessible-in-python/15265/34>`__
|
||||
for this PEP.
|
||||
- pyzmq `implements <https://github.com/zeromq/pyzmq/blob/fe18dc55516ef50d168fc02f8550a67ff5b5633d/zmq/backend/cffi/message.py#L190>`__
|
||||
a PyPy-compatible ``__buffer__`` method.
|
||||
- mpi4py `defines <https://github.com/mpi4py/mpi4py/blob/453b87d0da37c5914b91afb511b188556dff2a9c/src/mpi4py/typing.py#L66>`__
|
||||
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 <https://github.com/numpy/numpy/pull/13049>`__
|
||||
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 <https://github.com/python/mypy/pull/12661>`__
|
||||
with mypy shows that several major open source projects that use it
|
||||
|
|
Loading…
Reference in New Issue