On 3/18/19 6:08 PM, Steven D'Aprano wrote:
On Mon, Mar 18, 2019 at 03:12:52PM +0100, Antoine Pitrou wrote:

(also, don't forget you can still use the copy() + update() method)

If we had fluent method calls, we could write:

     process(mapping.copy().update(other))

but we don't, so we use a pointless temporary variable:

     temp = mapping.copy()
     temp.update(other)
     process(temp)
     del temp  # don't pollute the global namespace


turning what ought to be a simple expression into an extra two or three
statements.

So how many of you got tired of those three statements and
added something like the following function to your private
collection of useful functions:

    def merged_mappings(mapping, other):
        temp = mapping.copy()
        temp.update(other)
        return temp # no need to del temp here!

turning two or three statements into a simple expression?

I sure didn't.
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to