This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author anthonypjshaw
Recipients anthonypjshaw
Date 2017-04-09.23:26:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1491780376.9.0.908690557717.issue30029@psf.upfronthosting.co.za>
In-reply-to
Content
This is related to issue26188,

Using await in a simple statement (outside of an async def method) raises SyntaxError with the unhelpful message "invalid syntax".

It seems obvious once you've read PEP492 in detail, but I think that as more and more developers use async/await this will stump lots of people.

I've been trying to pick apart where this constraint is raised to see whether I can help with a PR, I've been through Grammar, Parser and then the AST and Compiler. 

Looking at https://github.com/python/cpython/blob/master/Python/compile.c#L4307-L4319 I can see there are helpful error messages, but during the tokenizer phase it checks that the syntax cannot be used unless you're within an async def method 
https://github.com/python/cpython/blob/6f0eb93183519024cb360162bdd81b9faec97ba6/Parser/tokenizer.c#L1574-L1583

I can't reproduce this in a REPL for 3.7.0a0, it never gets any further than the grammar or tokenizer phase.
History
Date User Action Args
2017-04-09 23:26:16anthonypjshawsetrecipients: + anthonypjshaw
2017-04-09 23:26:16anthonypjshawsetmessageid: <1491780376.9.0.908690557717.issue30029@psf.upfronthosting.co.za>
2017-04-09 23:26:16anthonypjshawlinkissue30029 messages
2017-04-09 23:26:16anthonypjshawcreate