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.

classification
Title: Compiler "'await' outside function" error message is unreachable
Type: Stage: resolved
Components: Versions: Python 3.7
process
Status: closed Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: anthonypjshaw
Priority: normal Keywords:

Created on 2017-04-09 23:26 by anthonypjshaw, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Pull Requests
URL Status Linked Edit
PR 1069 closed anthonypjshaw, 2017-04-10 00:11
Messages (2)
msg291398 - (view) Author: anthony shaw (anthonypjshaw) * (Python triager) Date: 2017-04-09 23:26
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.
msg291399 - (view) Author: anthony shaw (anthonypjshaw) * (Python triager) Date: 2017-04-10 00:02
yey! I figured it out!!
History
Date User Action Args
2022-04-11 14:58:45adminsetgithub: 74215
2017-04-10 01:04:13anthonypjshawsetstatus: open -> closed
stage: resolved
2017-04-10 00:11:32anthonypjshawsetpull_requests: + pull_request1215
2017-04-10 00:02:45anthonypjshawsetmessages: + msg291399
2017-04-09 23:26:16anthonypjshawcreate