"SyntaxError: 'await' outside function" when using Run cell
See original GitHub issueIssue Report Checklist
- Searched the issues page for similar reports
- Read the relevant sections of the Spyder Troubleshooting Guide and followed its advice
- Reproduced the issue after updating with
conda update spyder
(orpip
, if not using Anaconda) - Could not reproduce inside
jupyter qtconsole
(if console-related) - Tried basic troubleshooting (if a bug/error)
- Restarted Spyder
- Reset preferences with
spyder --reset
- Reinstalled the latest version of Anaconda
- Tried the other applicable steps from the Troubleshooting Guide
- Completed the Problem Description, Steps to Reproduce and Version sections below
Problem Description
IPython allows using await keyword outside functions, which is very helpful for debugging (%autoawait magic).
Consider the following snippet:
async def ping():
return "pong"
await ping()
What steps reproduce the problem?
- Create new file, copy above snippet
- Run > Run cell
What is the expected output? What do you see instead?
- Expected output: “pong”
- Actual result: SyntaxError: ‘await’ outside function
Note that selected the code and performing Run > Run selection (F9) gives the expected “pong”.
Running the file (Run >Run, F5) also gives a SyntaxError, which I consider being the correct behaviour.
As a comparison, Visual Code gives a SyntaxError when running the file, but runs successfully when running the cell. For me, this is the best behaviour, hence the present ticket.
Versions
Freshly installed from conda create -n spyder spyder
-
Spyder version: 4.2.3 None
-
Python version: 3.9.2 64-bit
-
Qt version: 5.9.7
-
PyQt5 version: 5.9.2
-
Operating System: Windows 10
-
IPython 7.21.0
Issue Analytics
- State:
- Created 3 years ago
- Comments:6 (5 by maintainers)
Top Results From Across the Web
Why can I only use the await keyword inside of async ...
This is of course a SyntaxError: 'await' outside async function . But—if this code could run—while the await expression is not placed inside...
Read more >'await' outside function error
I'm using the python environment and I'm having an error saying "SyntaxError: 'await' outside function". Does anyone know how to fix this?
Read more >SyntaxError: 'await' outside function · Issue #2971
I run the example in PySyft/examples/tutorials/advanced/websockets-example-MNIST-parallel/Asynchronous-federated-learning-on-MNIST.ipynb.
Read more >await - JavaScript - MDN Web Docs
Using await pauses the execution of its surrounding async function until the promise is settled (that is, fulfilled or rejected).
Read more >[ASYNCPRAW] Cannot use async or await in asyncpraw
I am trying to run this code given in the quickstart: from config import * import asyncpraw import ... SyntaxError: 'await' outside function....
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hey @nbud, thanks for reporting. I didn’t know that IPython allows you to do that.
For now, I think you need to switch from using the
runcell
command to paste the contents of cells directly into the console. For that, you need to go to the menu:and activate the option called
Copy full cell contents to the console when running code cells
.Ok, I understand that and it makes sense to me.
I think the only possible solution for now is to avoid using
runcell
, as I mentioned above. So I’m going to close this one.