[issue36144] Dictionary union. (PEP 584)

Brandt Bucher report at bugs.python.org
Thu Feb 27 12:49:23 EST 2020


Brandt Bucher <brandtbucher at gmail.com> added the comment:

> Im not sure if the dict(other) cast is the best way to go about it. Maybe this would work?

Yeah, I was imagining something like that... I used the cast for brevity in my reply but that probably wasn't helpful.

Note that for __or__, we probably want to check the type of the argument (for either dict or ChainMap, or maybe just Mapping), to keep it from working on an iterable of key-value pairs.

> I guess we need a __ror__ as well, in case there's some other mapping that doesn't implement __or__:

Agreed. Again, we can check for Mapping here to assure success for the copy() move.

> As a refinement, __or__ and __ror__ should perhaps check whether the operation can possibly succeed and return NotImplemented instead of raising? (Based on the type of other only, not its contents.)

Yup, see above. I think a check for Mapping should be fine.

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue36144>
_______________________________________


More information about the Python-bugs-list mailing list