[New-bugs-announce] [issue26188] Provide more helpful error message when `await` is called inside non-`async` method

Nicholas Chammas report at bugs.python.org
Sat Jan 23 21:06:03 EST 2016


New submission from Nicholas Chammas:

Here is the user interaction:

```python
$ python3
Python 3.5.1 (default, Dec  7 2015, 21:59:10) 
[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.1.76)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> def oh_hai():
...     await something()
  File "<stdin>", line 2
    await something()
                  ^
SyntaxError: invalid syntax
```

It would be helpful if Python could tell the user something more specific about _why_ the syntax is invalid. Is that possible?

For example, in the case above, an error message along the following lines would be much more helpful:

```
SyntaxError: Cannot call `await` inside non-`async` method.
```

Without a hint like this, it's too easy to miss the obvious and waste time eye-balling the code, like I did. :-)

----------
components: Interpreter Core
messages: 258879
nosy: Nicholas Chammas
priority: normal
severity: normal
status: open
title: Provide more helpful error message when `await` is called inside non-`async` method
versions: Python 3.5, Python 3.6

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue26188>
_______________________________________


More information about the New-bugs-announce mailing list