[Python-ideas] The @update operator for dictionaries

Jonathan Fine jfine2358 at gmail.com
Sat Mar 9 14:03:56 EST 2019

Acknowledgement of an error, and clarification of behaviour of '@b' vs
'@ b'. I claim that once '@b' is accepted as an operator, the
behaviour is perfectly natural and obvious.

In a previous post, I mispoke. I should have written
    a at b+1
is valid Python before and after, but with different syntax.
    (a @ b) + 1 # Before - operator is '@'.
    a @b (+1) # After - operator is '@b'.

Chris Angelico kindly pointed out that my Before value was wrong.
Thank you, Chris.

Chris also correctly points that
    '@ b' is parses as the '@' operator followed by the identifier 'b'
    '@b' parses as above (BEFORE)
    '@b' parses as the '@b' operator (AFTER)

He then correctly says that in my proposal the lack of whitespace
after an operator can cause the operator to absorb a following

However, something similar ALREADY happens in Python.
    >>> a = nota = True
    >>> not a
    >>> nota

Today, whenever a Python operator ends in a letter, and is followed by
an identifier, white space is or some other delimiter is required
between the two. Python, rightly, refuse to guess that 'notary' might
be 'not ary'.

Here is another example
    >>> e = note = None
    >>> e is not e
    >>> e is note

This is not quite what's happening with '@b'. With 'is not e' the
following identifier 'e' absorbs the 'not' from the operator to create

And finally
    >>> False is not None
    >>> False is (not None)

The 'natural language' operators appear in

In my suggestion, '@' consumes for as long it can, first a letter, and
then name characters. This is exactly the same as with 'a' or 'b'.

I think this is a problem, but not nearly so bad as Chris suggests.
Some people have argued that the proposed semantics for dict + dict
are natural and obvious, once the behaviour of Python elsewhere is
understood. I claim the same for '@b' and '@ b', once we allow '@b' as
an operator (which was the whole purpose of the proposal.

By the way, it's likely that most users won't know that '@' by itself
is an operator, until they come to use matrices.


More information about the Python-ideas mailing list