Hacktoberfest 2026: le issue che i maintainer hanno segnato per ottobre, aperte e adatte ai principianti. Sfoglia le issue Hacktoberfest

New asyncio rule: directly passing coroutine to `gather`, `shield`, `wait_for`, `wait`, or `as_completed`

Aperta
#319 1 commento 2 reazioni 0 assegnatari Vedi su GitHub

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
3/5
Tempo stimato
1-2 giorni
Idoneità per principianti
45/100
Tipo di issue
Funzionalità
Chiarezza
Abbastanza chiara
Stato di attività
Ferma
Stack tecnologico
python
Ambito
tooling

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

new rule postponed

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

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di python-trio/flake8-async

Tutte le issue di python-trio/flake8-async

Issue simili

Altre issue su Python

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.