[Python-ideas] Allow using ** twice

Nick Coghlan ncoghlan at gmail.com
Fri Jun 7 05:31:37 CEST 2013


On 7 June 2013 13:08, Haoyi Li <haoyi.sg at gmail.com> wrote:
> I agree with everything Nick said.
>
> Here's another idea I'll throw out there for option #3:
>
> dict_a.updated(dict_b)
>
> - Asymmetry is obvious (In contrast to `dict_a + dict_b` or `updated(dict_a,
> dict_b)`)
> - Concise with obvious intent (contrast with the various snippets pulled
> from SO)
> - update/updated mirrors sort/sorted reverse/reversed (contrast to
> `x.update(y)`/`collections.copy_and_update(x, y)`)
>
> There's a bit of unconventionality in that it's a method rather than a
> builtin (bullet 3), but even that has benefits in terms of making the
> asymmetry clear (bullet 1).

I did consider that, but I didn't like the idea of hinging such a
significant difference in semantics on a single "d". That's a bug
magnet if ever I saw one.

If you consider it as the possible name of a class method instead of
an instance method, you still have a bug magnet problem, in that
"dict_a.updated(dict_b)" would mean the same thing as
"dict.updated(dict_b)", which almost certainly isn't what the
programmer wanted.

By contrast, a collections.copy_and_update(dict_a, dict_b) function is
explicit and has the virtue of working with any ducktyped container
with copy() and update() methods, rather than being specific to dict
and collections.Mapping.

Cheers,
Nick.

--
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia


More information about the Python-ideas mailing list