[issue21678] Add operation "plus" for dictionaries

Михаил Мишакин report at bugs.python.org
Fri Jun 6 12:17:45 CEST 2014


New submission from Михаил Мишакин:

First of all, i'm sorry for my English :)

I would like to union dictionaries with operator + (and +=) like this:

>>> dict(a=1, b=2) + {'a': 10, 'c': 30}
{'a': 10, 'b': 2, 'c': 30}

>>> d = dict(a=1, b=2, c={'c1': 3, 'c2': 4})
>>> d += dict(a=10, c={'c1':30})
>>> d
{'a': 10, 'b': 2, c: {'c1':30}}


Also, it gives an easy way to modify and extend the class attributes:

class Super:
   params = {
       'name': 'John',
       'surname': 'Doe',
   }

class Sub(Super):
   params = Super.params + {
       'surname': 'Show',
       'age': 32,
   }

----------
components: Interpreter Core
messages: 219867
nosy: Pix
priority: normal
severity: normal
status: open
title: Add operation "plus" for dictionaries
versions: Python 3.4

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue21678>
_______________________________________


More information about the Python-bugs-list mailing list