Error code for "async for" outside async function is too general
まだ誰も着手していません。
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
The error code for "async for" outside async function [syntax] is very general, so it is hard to disable without allowing other syntax errors.
This is important to me because I want to type check Jupyter notebooks that take advantage of the autoawait feature and are written in the percent file format. With the error code being syntax, I would have to allow many unrelated errors to disable this error using disable_error_code.
I think it would be good if it used the same error code as "await" outside function [top-level-await], or perhaps a new code entirely.
To Reproduce
Example percent encoded notebook:
# %%
async def foo():
return 1
await foo()
# %%
async def values():
yield 1
yield 2
async for v in values():
print(v)
https://mypy-play.net/?mypy=latest&python=3.12&gist=ddd45a5b59946d0b423e5494af96e286
Expected Behavior
main.py:6: error: "await" outside function [top-level-await]
main.py:15: error: "async for" outside async function [top-level-await]
Actual Behavior
main.py:6: error: "await" outside function [top-level-await]
main.py:15: error: "async for" outside async function [syntax]
Your Environment
- Mypy version used: 1.15.0
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini(and other config files): None - Python version used: 3.12.9
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、提供された percent-encoded notebook の例を mypy 1.15.0 と Python 3.12 で再現します。top-level await と async for の診断がどのように割り当てられるかを追跡し、その後、async-for のエラーが期待どおり [top-level-await] を報告することを、無関係な構文診断を変更せずに確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- tooling
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 48/100