PEP 584: Add info regarding Mapping/MutableMapping (#1331)

Also add a note about other stdlib mappings having these added.
This commit is contained in:
Brandt Bucher 2020-03-14 13:03:12 -07:00 committed by GitHub
parent 7f7a08efd1
commit 4516435ea1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 0 deletions

View File

@ -21,6 +21,11 @@ Abstract
This PEP proposes adding merge (``|``) and update (``|=``) operators
to the built-in ``dict`` class.
.. note::
After this PEP was accepted, the decision was made to also
implement the new operators for `several other standard library
mappings <https://bugs.python.org/issue36144>`_.
==========
Motivation
@ -421,6 +426,30 @@ seen wins", however, has the advantage of consistency with other dict
operations (and the proposed union operators).
----------------------------------------------
What About ``Mapping`` And ``MutableMapping``?
----------------------------------------------
``collections.abc.Mapping`` and ``collections.abc.MutableMapping``
should define ``|`` and ``|=``, so subclasses could just inherit the
new operators instead of having to define them.
''''''''
Response
''''''''
There are two primary reasons why adding the new operators to these
classes would be problematic:
- Currently, neither defines a ``copy`` method, which would be
necessary for ``|`` to create a new instance.
- Adding ``|=`` to ``MutableMapping`` (or a ``copy`` method to
``Mapping``) would create compatibility issues for virtual
subclasses.
==============
Rejected Ideas
==============