[Python-ideas] The @update operator for dictionaries

Steven D'Aprano steve at pearwood.info
Sat Mar 9 11:07:01 EST 2019


On Sat, Mar 09, 2019 at 03:33:25PM +0000, Jonathan Fine wrote:
> I've been thinking that it might be easier, in the long term, to make
> a big step and allow
>     >>> a @update= b
> as valid Python. What do you think? (I hope it will look nicer once
> syntax highlighted.)

Are we supposed to know what that does?


> For clarity, this would proceed via a.__iat_update__(b), and (a
> @update b) would be similarly defined.

For an explanation to be clear, you actually have to give an 
explanation. You can start with explaining the difference between the 
two different examples you give:

    a at update=b
    a at update b

and what the default __iat_update__ does.

Is this supposed to be unique to update, or will there be an infinite 
number of special dunder methods for arbitrary method names?

     a at spam=b  # calls __iat_spam__

Does this apply to only dicts, or is it applicable to every object?


> As major disadvantage, of course, will be that
>     >>> guido at python.org
> would no longer be valid Python!

New syntax which breaks existing code is not likely to be 
accepted without a *really* good reason.


-- 
Steven


More information about the Python-ideas mailing list