currently dicts have insert-or-update semantics, e.g.:

>>> dict([((), 1), ((), 2)])
{(): 2}

this is fine. however, in many cases insert or insert-or-ignore are more useful: (hypothetical examples)

>>> InsertOrIgnoreDict([((), 1), ((), 2)])
{(): 1}

>>> InsertDict([((), 1), ((), 2)])
Traceback: [...]
ValueError: key exists

these are useful when dealing with custom config file formats, config overrides, among other things.

additionally we could also get an UpdateDict, a *view* into a dict that only allows updating existing entries:

>>> a = {'a': 1}
>>> b = {'a': 2, 'b': 3}
>>> UpdateDict(a).update(b)
>>> a
{'a': 2}

but I don't see an obvious usefulness to this one. it'd just be for consistency with other SQL-esque dict wrappers (like the above InsertOrIgnoreDict and InsertDict).
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/7PCWDORFLBFY6HRLNNS6UBL2CRER26SM/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to