Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruff reports F704 await statement outside of a function for notebooks #6584

Closed
david-waterworth opened this issue Aug 15, 2023 · 2 comments · Fixed by #6607
Closed

Ruff reports F704 await statement outside of a function for notebooks #6584

david-waterworth opened this issue Aug 15, 2023 · 2 comments · Fixed by #6607
Labels
bug Something isn't working

Comments

@david-waterworth
Copy link

david-waterworth commented Aug 15, 2023

In notebooks await is allowed in a cell (i.e. outside of a function), but ruff reports F704 - see also microsoft/pylance-release#1754 and https://ipython.readthedocs.io/en/stable/interactive/autoawait.html

@charliermarsh charliermarsh added the bug Something isn't working label Aug 15, 2023
@charliermarsh
Copy link
Member

Wow, interesting, TIL. Thanks for filing.

@dhruvmanila
Copy link
Member

Interesting! It also seems that this can be disabled using %autoawait False or using c.InteractiveShell.autoawait in the config file.

I'm not sure what the long term solution would be but one idea is to store these as a context while processing the Notebook and then using that in some kind of a middleware to filter out such diagnostics. Or, instead of middleware this context can be passed around to the checkers. For example, in this example the context would give us information if autoawait is disabled or not. This will still be limited as it can be disabled in the config file.

charliermarsh added a commit that referenced this issue Aug 16, 2023
## Summary

Top-level `await` is allowed in Jupyter notebooks (see:
[autoawait](https://ipython.readthedocs.io/en/stable/interactive/autoawait.html)).

Closes #6584.

## Test Plan

Had to test this manually. Created a notebook, verified that the `yield`
was flagged but the `await` was not.

<img width="868" alt="Screen Shot 2023-08-15 at 11 40 19 PM"
src="https://github.com/astral-sh/ruff/assets/1309177/b2853651-30a6-4dc6-851c-9fe7f694b8e8">
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants