
On 02/12/2015 04:29 PM, Donald Stufft wrote:
On Feb 12, 2015, at 6:28 PM, Eric Snow <ericsnowcurrently@gmail.com> wrote:
On Thu, Feb 12, 2015 at 5:25 AM, Donald Stufft <donald@stufft.io> wrote:
I’ve wanted this several times, explicitly the copying variant of it. I always get slightly annoyed whenever I have to manually spell out the copy and the update.
copy-and-update:
dict(old_dict, **other_dict)
Only works if other_dict’s keys are all valid keyword arguments and AFAIK is considered an implementation detail of CPython.
To be clear, kwargs to the dict() constructor are not an implementation detail of CPython. The implementation detail of CPython (2.x only) is that this technique works at all if other_dict has keys which are not strings. That has been changed for consistency in Python 3, and never worked in any of the alternative Python implementations AFAIK. So you're right that this technique is not usable as a general-purpose copy-and-update. Also, Guido doesn't like it: http://mail.python.org/pipermail/python-dev/2010-April/099459.html I think the fact that it is so often recommended is another bit of evidence that there is demand for copy-and-update-as-expression, though. Carl