[Python-Dev] PEP 492 vs. PEP 3152, new round (original) (raw)

Yury Selivanov yselivanov.ml at gmail.com
Thu Apr 30 20:04:58 CEST 2015


On 2015-04-30 1:56 PM, Ethan Furman wrote:

>Why not? Unlike some other languages, Python does not have uniform >priorities for unary operators, so it's reasonable for some unary >operations to have a different priority than others, and certain things >will be SyntaxErrors because of that. E.g. you can write "not -x" but you >can't write "- not x". For one, Yury's answer is "- await x" which looks just as nonsensical as "- not x".

"- await x" is a perfectly valid code:

 result = - await compute_in_db()

(same as "result = - (yield from do_something())")

For another, an error of some type will be raised if either neg doesn't exist or it doesn't return an awaitable, so a SyntaxError is unnecessary. For a third, by making it a SyntaxError you are forcing the use of parens to get what should be the behavior anyway.

I still want to see where my current grammar forces to use parens. See [1], there are no useless parens anywhere.

FWIW, I'll fix the 'await (await x)' expression to be parsed without parens.

In other words, a SyntaxError is nat any clearer than "AttributeError: obj has no neg method" and it's not any clearer than "AwaitError: neg returned not-awaitable". Those last two errors tell you exactly what you did wrong.

This is debatable. "obj has no neg method" isn't obvious to everyone (especially to those people who aren't using operator overloading).

[1] https://www.python.org/dev/peps/pep-0492/#examples-of-await-expressions

Yury



More information about the Python-Dev mailing list