"Awaitable" is insufficiently expressive, as one may await something other than Futures
Dieses Issue hat noch niemand übernommen.
Bewertung
- Schwierigkeit
- 5/5
- Geschätzter Aufwand
- Über eine Woche
- Anfängerfreundlichkeit
- 25/100
Rechercherichtung
Beginnen Sie mit der Lektüre der im Issue beschriebenen Definition von Awaitable und des await-Protokolls und vergleichen Sie anschließend, wie Future, Deferred, curio traps und Trio traps dargestellt werden. Die Arbeit ist erst abgeschlossen, wenn ein abgestimmtes Modell dafür vorliegt, wie inkompatible Scheduling-Protokolle ausgedrückt werden können, während kompatible Awaitables erhalten bleiben; es wird keine Datei oder kein Test angegeben.
Vom Indexierungsmodell aus dem Issue-Text verfasst.
Beschreibung
In the wild, today, if you await something, there are several potentially valid things to bubble back out from the innermost await
- an
asyncio.Future - a curio "trap" (which I gather is defined as something like
Tuple[curio.traps.Traps, Any, ...]) - a Trio trap, (which I gather is defined as something like
Iterable[WaitTaskRescheduled]although I haven't quite found the bottom of that stack) - a
Deferred
Not all of these are mutually compatible. However, Awaitable is parameterized only on one type - the type of its result. This results in code like this:
def some_deferred() -> Awaitable[int]: ...
def some_future() -> Awaitable[int]: ...
async def x() -> Awaitable[List[int]]:
y = []
y.append(await some_deferred())
y.append(await some_future())
return y
type-checking even though it should fail.
I'd like to be able to express this as
def some_deferred() -> Awaitable[int, Deferred]: ...
def some_future() -> Awaitable[int]: ... # presumably Future is the default
async def x() -> Awaitable[List[int]]:
y = []
y.append(await some_deferred()) # <-- automatically specialize to `Awaitable[List[int], Deferred]` here, if possible?
y.append(await some_future()) # <-- type error!
return y
This is made slightly more complex by the fact that some awaitables are mutually intelligible - for example, anything that awaits a Deferred should eventually be able to await a Future directly, once we've made a few more changes to Twisted. We could also do this in the other direction if __await__ were changed to pass the loop along. Whereas, some of these types are incompatible by design; my understanding is that await implies a completely different, and somewhat higher-level, scheduling protocol in Trio, for example.
- Vorherrschende Sprache
- Python
- Sterne
- 1.8k
- Forks
- 302
- Ø Merge
- 23 Std.
- Gemergte PRs (30 T.)
- 8
Beitragsleitfaden
Für dieses Repository ist kein Beitragsleitfaden indexiert
Erste Schritte
- Lesen Sie das ganze Issue und danach den Beitragsleitfaden des Projekts.
- Schreiben Sie ins Issue, dass Sie es übernehmen — das erspart doppelte Arbeit.
- Forken Sie das Repository und arbeiten Sie in einem Branch.
- Öffnen Sie einen Pull Request, der die Issue-Nummer nennt.
Mehr aus python/typing
-
topic: typing spec
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 72/100
-
topic: typing spec
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 75/100
-
topic: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 76/100
-
topic: documentation
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 65/100
-
topic: conformance tests topic: typing spec
Schwierigkeit 3/5 1-2 Tage Anfängerfreundlichkeit 72/100
Ähnliche Issues
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
syfoud/Simulated_Scepter#172 ·
-
A cancelled tests run makes the coverage comment workflow fail and reports it as a red check on main Offenarea: ci bug perceived difficulty: 3
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
Nitjsefnie-Harness-Commons/daedalus#921 · 1 Kommentar ·
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 86/100
EleutherAI/lm-evaluation-harness#4207 ·
-
Schwierigkeit 1/5 Unter einer Stunde Anfängerfreundlichkeit 92/100
-
Schwierigkeit 2/5 1-3 Stunden Anfängerfreundlichkeit 78/100
ClickHouse/clickhouse-connect#1057 ·