-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
'await' in non-async function is a blocking error #15339
Comments
Hello, I'd like to begin working on this issue, would that be fine? |
I have created a PR that references the issue, however, I have not added any tests for the new error code, any guidance on how to proceed would be appreciated. Thank you! |
Thank you. Several other keywords may also cause similar blocking issues, such as "yield" and "break." I think these should also be taken into consideration. For example:
|
Hello, when I try to implement an error code for each of these blocking issues I encounter an "IndexError: List out of range" error. I believe this is due to handle_continue attempting to iterate through a list when it has no contents however I am not certain if this is the case. This occurred for all 3 example scenarios described by @xiaxinmeng. I am not sure how to proceed. |
I'm generally in support of reducing the number of blocking errors, but if it requires complex changes to how we deal with loops, it's probably not worth changing anything here. Such code is a SyntaxError at runtime anyway. |
That sounds good, and I have a question about the original scenario's "await" not in-async error. I created an error code AWAIT_NOT_ASYNC and assigned it to one of the cases in the visit_await_expr function located in semanal.py and I saw no errors with that code. However, I have not yet added test cases for the function I added. Any guidance on where to add test cases would be appreciated. |
I think if you fix the test case that is failing on your PR that should be enough (testInvalidComprehensionNoCrash) |
I have closed the old PR that referenced the error and added a new PR that includes:
I believe the changes in the PR should close this issue. Please let me know if any more work should be done on this issue. |
Fixed by #15384 |
await in a function (not a async def) causes an error "errors prevented further checking". I think the expected behavior here is to assign an error code in this case rather than to halt.
To Reproduce
Run the following file with "mypy example.py":
Expected Behavior:
MyPy does not halt checking, and it uses an error-code for "await" outside function.
Actual Behavior
Environment
Mypy version: 1.3.0
Python version: 3.11.3
Operating System: Ubuntu 18.04
How to install MyPy: "python3.11 -m pip install mypy"
The text was updated successfully, but these errors were encountered: