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

mypy 1.0.0 does not include error code for "await" outside function so it cannot be ignored when linting notebooks #14763

Closed
sjdemartini opened this issue Feb 22, 2023 · 1 comment · Fixed by #14801
Labels
bug mypy got something wrong topic-async async, await, asyncio

Comments

@sjdemartini
Copy link

Bug Report

In mypy 0.991, mypy would assign error code "misc" when await was used outside a function. Though "misc" is non-specific, having an error code allowed for ignoring these errors when linting Jupyter notebook files (using nbqa mypy file.ipynb with nbqa). Jupyter notebooks already automatically run cells in an async awaited eventloop context (see here), so it's important to be able to ignore these top-level await usages in ipynb files. For instance, Pylance added logic to handle this situation directly here microsoft/pylance-release#1754 (comment).

As of mypy 1.0.0, mypy no longer assigns an error code when await is used outside a function, and treats it as a blocking error that prevents further checking. This means it's now no longer possible to lint notebook files that use await with mypy+nbqa.

I'm guessing this change in behavior was introduced in #14486 here

To Reproduce

Run await in the top level of some file (notebook or otherwise):

async def foo():
    pass

await foo()

Compare:

Expected Behavior

mypy does not halt further checking, and mypy uses an error-code for "await" outside function, so that users can choose to disable the warning when that occurs. That will allow mypy to continue to be used/useful for Jupyter notebook files (for instance, setting --disable-error-code=misc when using nbqa).

Actual Behavior

mypy returns a blocking error and does not provide a workaround.

Your Environment

  • Mypy version used: 1.0.1 or 1.0.0
  • Mypy command-line flags: --disable-error-code=misc
  • Mypy configuration options from mypy.ini (and other config files): any
  • Python version used: 3.10+
@sjdemartini sjdemartini added the bug mypy got something wrong label Feb 22, 2023
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Feb 22, 2023

cc @JukkaL reasonable use case for this to be a non-blocking error

@AlexWaygood AlexWaygood added the topic-async async, await, asyncio label Feb 22, 2023
JelleZijlstra pushed a commit that referenced this issue Feb 28, 2023
Now users can disable the first kind of error, but not the second kind
(which is always a syntax error).

Refs #14486
Closes #14763
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong topic-async async, await, asyncio
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants