On 04/30, Guido van Rossum wrote:
On Thu, Apr 30, 2015 at 9:15 AM, Ethan Furman wrote:
[...] Both you and Paul are correct on this, thank you. The proper resolution of
await -coro()
is indeed to get the result of coro(), call it's __neg__ method, and then await on that.
And that is perfectly reasonable, and should not be a SyntaxError; what it might be is an AttributeError (no __neg__ method) or an AsyncError (__neg__ returned non-awaitable object), or might even just work [1]... but it definitely should /not/ be a SyntaxError.
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". 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. 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. -- ~Ethan~