New asyncio rule: directly passing coroutine to `gather`, `shield`, `wait_for`, `wait`, or `as_completed`
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 45/100
Direzione di ricerca
Inizia individuando le implementazioni esistenti delle regole asyncio e i relativi test. Traccia la gestione degli argomenti coroutine diretti per gather, shield, wait_for, wait e as_completed, quindi verifica il comportamento previsto nelle diverse versioni di Python, incluso wait su Python 3.11+. Il lavoro è completo quando la nuova regola rileva le chiamate dirette descritte e i compromessi relativi ai falsi positivi sono coperti dai test.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Tasks without saved reference can be garbage collected, and several functions in asyncio automatically converts coroutines into tasks - which means it's ~impossible to save a strong reference to those tasks. See e.g. https://docs.python.org/3/library/asyncio-task.html#asyncio.shield
The rule implementation would be fairly straightforward, just check for calls in the parameter list: asyncio.shield(anything()). This will give false alarms if anything is not a coroutine, but instead a sync function that creates a task, saves it globally, and returns it, but I suspect that's a minority of cases. We could save the names of any sync funcs to reduce the false alarm rate, but that wouldn't work when the functions are imported from other files.
We could also use type-checking to catch
a = my_coro()
asyncio.wait_for(a)
On py311+ asyncio.wait errors if directly passed coroutines.
There appears to be movement in making the event loop save strong references, but that'll probably only affect py3.14/py3.15 or later https://github.com/python/cpython/pull/121264
- Lingua principale
- Python
- Stelle
- 26
- Fork
- 10
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Apri la guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di python-trio/flake8-async
-
Rename ASYNC126 to ASYNC4xx Apertarule improvement
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
python-trio/flake8-async#457 · 1 reazione ·
-
Difficoltà 3/5 1-2 giorni Idoneità per principianti 68/100
python-trio/flake8-async#475 · 1 commento ·
-
Warn about unused `noqa`s Apertanew rule
Difficoltà 3/5 1-2 giorni Idoneità per principianti 55/100
python-trio/flake8-async#454 · 1 commento ·
-
ASYNC103 for sync functions Apertarule improvement
Difficoltà 3/5 1-2 giorni Idoneità per principianti 62/100
python-trio/flake8-async#447 · 5 commenti ·
-
good first issue
Difficoltà 5/5 Più di una settimana Idoneità per principianti 15/100
python-trio/flake8-async#396 · 1 commento ·
Tutte le issue di python-trio/flake8-async
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
xinnan-tech/xiaozhi-fde-talk#263 ·
-
rules
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
huggingface/Repo2RLEnv#163 · 1 commento ·
-
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 95/100
huggingface/sentence-transformers#4074 ·
-
comp/dashboard invalid P3
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
NousResearch/hermes-agent#121143 ·