Brandt Bucher <brandtbuc...@gmail.com> added the comment:

> Note that in your last message, `d1 |= cm2` will fail for this reason. You 
> can of course fix that with `d1 |= dict(cm2)`, although IIUC there's no 
> reason one of the maps couldn't be some other [Mutable]Mapping.

Mappings and iterables are fine for the in-place variant. :)

>>> from collections import ChainMap
>>> d = {}
>>> c = ChainMap({"r": 2, "d":2})
>>> d |= c
>>> d
{'r': 2, 'd': 2}

I think it would be confusing to have `ChainMap | ChainMap` behave subtly 
different than `dict | ChainMap`. It would be *especially* odd if it also 
differed subtly from `ChainMap | dict`.

To recap:

+1 on adding the operators with dict semantics,
+0 on no PEP 584 for ChainMap.
-0 on implementing them, but changing the winning behavior by concatenating the 
maps lists or something. This would probably make more sense to me as a `+` 
operator, honestly. :(
-1 for having the operators behave differently (other than performance 
shortcuts) for `cm | d`, `cm | cm`, `cm |= d`, `cm |= cm`.

----------

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36144>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to