
17.02.20 23:02, Guido van Rossum пише:
Now that the last bits of discussion about PEP 584 have been settled (we will *not* be calling the `copy` or `update` methods) I am accepting this PEP. Congratulations Steven and Brandt!
Thanks to everyone else who gave their opinion.
Formally, I will just send my recommendation to accept the PEP to the Steering Council -- they will then let us know whether they agree, and once that's done we can update the PEP with the "Accepted" status and land the implementation (https://github.com/python/cpython/pull/12088). (Hm, the PEP should probably also link to that PR rather than to Brandt's private branch.)
Comments to the PEP. In the disadvantages of existing syntax `{**d1, **d2}` (https://www.python.org/dev/peps/pep-0584/#d1-d2) it claims:
{**d1, **d2} ignores the types of the mappings and always returns a dict. type(d1)({**d1, **d2}) fails for dict subclasses such as defaultdict that have an incompatible __init__ method.
But it was decided that `d1 | d2` also should ignore the types of the operands and always return a dict. And it accepts only dicts, not general mappings, in difference to `{**d1, **d2}`. So the only disadvantage of `{**d1, **d2}` is that it is not well known and "looks ugly". But it supports general mappings. There is a similar note about ChainMap (https://www.python.org/dev/peps/pep-0584/#collections-chainmap)
Like dict unpacking, it is tricky to get it to honor the desired subclass. For the same reason, type(d1)(ChainMap(d2, d1)) fails for some subclasses of dict.
which is not relevant to the final implementation of PEP 584. The pure-Python implementation of the non-inplace operator can be simpler if use dict unpacking: def __or__(self, other): if not isinstance(other, dict): return NotImplemented return {**self, **other} def __ror__(self, other): if not isinstance(other, dict): return NotImplemented return {**other, **self} I suggest to include to objections that non-inplace merging of two dicts is much less common operation than concatenating of two strings or other sequences, and that the existing syntax `{**d1, **d2}` completely satisfies the need. The in-place operator is completely equivalent to dict.update(). So the possible benefit of adding support of two operators for dict is much less than common bar for changes in the builtin types. This is why I still -0 for this feature. In the initial form it contradicted the behavior of other builtin types and operators, but after fixing contradictions it became pretty useless.