await-not-async missed & false alarms with genexp and list comprehensions
オープン
まだ誰も着手していません。
bug
good-first-issue
topic-async
topic-runtime-semantics
- 主要言語
- Python
- スター
- 20.6k
- フォーク
- 3.3k
- PR マージ指標
- PR 指標を取得中
説明
Bug Report
await-not-async does not warn on async for in list and dict comprehensions, and incorrectly does give a warning for await inside GeneratorExp.elt.
For list & dict comprehensions you should error on any await or async for, but for generator expressions it's only the generator that should be checked.
To Reproduce
def foo():
...
def should_not_error():
(await x for x in foo())
def should_error():
[x async for x in foo()]
{k: v async for k, v in foo()}
def correctly_errors():
(x for x in await foo())
[await x for x in foo()]
def correctly_does_not_error():
(x async for x in foo())
Expected Behavior
It should error on 8, 9, 12 and 13
Actual Behavior
$ mypy foofoo.py
foofoo.py:5: error: "await" outside coroutine ("async def") [await-not-async]
foofoo.py:12: error: "await" outside coroutine ("async def") [await-not-async]
foofoo.py:13: error: "await" outside coroutine ("async def") [await-not-async]
Found 3 errors in 1 file (checked 1 source file)
Your Environment
$ mypy --version
mypy 1.13.0 (compiled: yes)
- Mypy version used:
- Mypy command-line flags:
- Mypy configuration options from
mypy.ini(and other config files): - Python version used:
also see https://github.com/astral-sh/ruff/issues/14167 that had the exact same issues
コントリビューションガイド
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
調査の方向性
まず、await-not-async の実装と、GeneratorExp.elt、リスト内包表記、辞書内包表記の処理を見つけます。提示された例を mypy で再現し、8、9、12、13 行目で診断が発生する一方、5 行目と 14 行目のジェネレーター式のケースでは警告が発生しないことを確認します。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- python
- 領域
- devtools
- issue の種類
- バグ
- 難易度
- 3/5
- 見積もり時間
- 1〜2日
- 活発さ
- 静か
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 58/100