[Python-ideas] Suggestions: dict.flow_update and dict.__add__
Jonathan Fine
jfine2358 at gmail.com
Fri Mar 8 04:48:58 EST 2019
I've just learnt something new. Look at
>>> from operator import iadd
>>> lst = [1, 2, 3]
>>> iadd(lst, 'hi')
[1, 2, 3, 'h', 'i']
>>> lst
[1, 2, 3, 'h', 'i']
This shows that the proposals dict.flow_update and dict.__iadd__ are
basically the same. (I think this is quite important for understanding
the attraction of fluent programming. We ALREADY like and use it, in
the form of augmented assignment of mutables.)
This also shows that
combined = defaults.copy()
combined.update(options)
could, if the proposal is accepted, be written as
defaults.copy().__iadd__(options)
I got the idea from the withdrawn PEP (thank you, Nick Coghlan, for writing it):
PEP 577 -- Augmented Assignment Expressions
https://www.python.org/dev/peps/pep-0577/
--
Jonathan
More information about the Python-ideas
mailing list