PEP 584: Add info regarding Mapping/MutableMapping (#1331)
Also add a note about other stdlib mappings having these added.
This commit is contained in:
parent
7f7a08efd1
commit
4516435ea1
29
pep-0584.rst
29
pep-0584.rst
|
@ -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
|
||||
==============
|
||||
|
|
Loading…
Reference in New Issue