On Thu, Nov 7, 2019 at 8:47 AM Greg Ewing <greg.ew...@canterbury.ac.nz> wrote:
>
> Andrew Barnert via Python-ideas wrote:
> > On Nov 6, 2019, at 08:59, Chris Angelico <ros...@gmail.com> wrote:
> >
> >> No, because "x <-- y" is already legal syntax
> >
> > You could handle that by making the grammar more complicated.
>
> Or just have the tokeniser treat "<--" as a single token, the
> same way that it treats "<=" as a single token rather than
> "<" followed by "=". It would be a backwards-incompatible
> change (if you really wanted "less than minus minus something"
> you'd have to put a space in somewhere) but replacing the
> assignment operator is already a much bigger one.
>

To clarify: I wasn't saying that it's fundamentally impossible to have
these kinds of parsing rules, but that it's backward incompatible.
Notably, even though this syntax is fairly unlikely to come up, it
means that anyone using "<--" as an assignment operator will have to
worry about older Python versions misinterpreting it. If you create a
brand new operator out of something that's currently invalid syntax,
then it's easy - you get an instant compilation error on an older
interpreter. With this, it might sometimes result in a runtime
NameError or TypeError, and even worse, might just silently do the
wrong thing. That's why Python 3.9 still won't let you write "except
ValueError, IndexError:" - you *have* to parenthesize the tuple,
because the comma syntax had a different meaning in Python 2 (the
"except Exception as name:" syntax was backported to 2.6/2.7 but the
older syntax is of course still valid). There is no way that you can
accidentally run your code on the wrong Python and have it silently
assign to IndexError instead of catching two types.

ChrisA
_______________________________________________
Python-ideas mailing list -- python-ideas@python.org
To unsubscribe send an email to python-ideas-le...@python.org
https://mail.python.org/mailman3/lists/python-ideas.python.org/
Message archived at 
https://mail.python.org/archives/list/python-ideas@python.org/message/EN3YZ7MUSOFBEX3QTT5OYCPDZCQVWN3I/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to