[issue36144] Dictionary addition.

Raymond Hettinger report at bugs.python.org
Thu Feb 28 02:36:52 EST 2019


Raymond Hettinger <raymond.hettinger at gmail.com> added the comment:

For the record, I'm opposed to the idea.

* Use of the + operator is a temptation to produce new dictionaries rather than update an existing dict in-place which is usually what you want.

* We already have ChainMap() which presents a single view of multiple mappings with any copying.

* It is natural to expect the plus operator to be commutative, but this operation would necessarily be non-commutative.

* Many other APIs are modeled on the dict API, so we should not grow the API unless there is a big win.  The effects would be pervasive.

* I don't see other languages going down this path, nor am I seeing dict subclasses that implement this functionality.  Those are indications that this more of a "fun thing we could do" rather than a "thing that people need".

* The existing code already reads nicely:

     options.update(user_selections)

  That reads more like self explanatory English than:

     options += user_selections

  The latter takes more effort to correctly parse and
  makes it less clear that you're working with dicts.

* It isn't self-evident that the right operand needs to be another dictionary. If a person is trying to "add a key / value pair" to an existing dictionary, the "+=" operator would be tempting but it wouldn't work.

----------

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


More information about the Python-bugs-list mailing list