await-not-async missed & false alarms with genexp and list comprehensions
Dieses Issue hat noch niemand übernommen.
- Vorherrschende Sprache
- Python
- Sterne
- 20.6k
- Forks
- 3.3k
- PR-Merge-Kennzahlen
- PR-Kennzahlen ausstehend
Beschreibung
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
Beitragsleitfaden
Erste Schritte
- Lies das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreib ins Issue, dass du es übernimmst — das erspart doppelte Arbeit.
- Forke das Repository und arbeite in einem Branch.
- Öffne einen Pull Request, der die Issue-Nummer nennt.
Rechercherichtung
Beginne damit, die Implementierung von await-not-async und die Behandlung von GeneratorExp.elt, List Comprehensions und Dict Comprehensions zu lokalisieren. Führe das bereitgestellte Beispiel mit mypy aus und überprüfe anschließend, dass Diagnosen in den Zeilen 8, 9, 12 und 13 auftreten, während die Generator-Expression-Fälle in den Zeilen 5 und 14 keine Warnung ausgeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Bewertung
- Tech-Stack
- python
- Bereich
- devtools
- Issue-Typ
- Bug
- Schwierigkeit
- 3/5
- Geschätzter Aufwand
- 1-2 Tage
- Aktivitätsstatus
- Ruhig
- Klarheit
- Größtenteils klar
- Anfängerfreundlichkeit
- 58/100