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