10
10
import weakref
11
11
from contextlib import ExitStack , contextmanager , suppress
12
12
from math import inf , nan
13
- from typing import TYPE_CHECKING , Any , NoReturn , TypeVar , cast
13
+ from typing import TYPE_CHECKING , NoReturn , TypeVar
14
14
15
15
import outcome
16
16
import pytest
@@ -2295,7 +2295,8 @@ async def detachable_coroutine(
2295
2295
await sleep (0 )
2296
2296
nonlocal task , pdco_outcome
2297
2297
task = _core .current_task ()
2298
- pdco_outcome = await outcome .acapture (
2298
+ # `No overload variant of "acapture" matches argument types "Callable[[Outcome[object]], Coroutine[Any, Any, object]]", "Outcome[None]"`
2299
+ pdco_outcome = await outcome .acapture ( # type: ignore[call-overload]
2299
2300
_core .permanently_detach_coroutine_object ,
2300
2301
task_outcome ,
2301
2302
)
@@ -2308,18 +2309,11 @@ async def detachable_coroutine(
2308
2309
# is still iterable. At that point anything can be sent into the coroutine, so the .coro type
2309
2310
# is wrong.
2310
2311
assert pdco_outcome is None
2311
- # Explicit "Any" is not allowed
2312
- assert (
2313
- not_none (task ).coro .send (
2314
- cast (Any , "be free!" ), # type: ignore[misc]
2315
- )
2316
- == "I'm free!"
2317
- )
2312
+ # `Argument 1 to "send" of "Coroutine" has incompatible type "str"; expected "Outcome[object]"`
2313
+ assert not_none (task ).coro .send ("be free!" ) == "I'm free!" # type: ignore[arg-type]
2318
2314
assert pdco_outcome == outcome .Value ("be free!" )
2319
2315
with pytest .raises (StopIteration ):
2320
- not_none (task ).coro .send (
2321
- cast (Any , None ), # type: ignore[misc]
2322
- )
2316
+ not_none (task ).coro .send (None ) # type: ignore[arg-type]
2323
2317
2324
2318
# Check the exception paths too
2325
2319
task = None
@@ -2332,7 +2326,7 @@ async def detachable_coroutine(
2332
2326
assert not_none (task ).coro .throw (throw_in ) == "uh oh"
2333
2327
assert pdco_outcome == outcome .Error (throw_in )
2334
2328
with pytest .raises (StopIteration ):
2335
- task .coro .send (cast ( Any , None ) )
2329
+ task .coro .send (None )
2336
2330
2337
2331
async def bad_detach () -> None :
2338
2332
async with _core .open_nursery ():
@@ -2384,25 +2378,10 @@ def abort_fn(_: _core.RaiseCancelT) -> _core.Abort: # pragma: no cover
2384
2378
await wait_all_tasks_blocked ()
2385
2379
2386
2380
# Okay, it's detached. Here's our coroutine runner:
2387
- # Explicit "Any" is not allowed
2388
- assert (
2389
- not_none (task ).coro .send (
2390
- cast (Any , "not trio!" ), # type: ignore[misc]
2391
- )
2392
- == 1
2393
- )
2394
- assert (
2395
- not_none (task ).coro .send (
2396
- cast (Any , None ), # type: ignore[misc]
2397
- )
2398
- == 2
2399
- )
2400
- assert (
2401
- not_none (task ).coro .send (
2402
- cast (Any , None ), # type: ignore[misc]
2403
- )
2404
- == "byebye"
2405
- )
2381
+ # `Argument 1 to "send" of "Coroutine" has incompatible type "str"; expected "Outcome[object]"`
2382
+ assert not_none (task ).coro .send ("not trio!" ) == 1 # type: ignore[arg-type]
2383
+ assert not_none (task ).coro .send (None ) == 2 # type: ignore[arg-type]
2384
+ assert not_none (task ).coro .send (None ) == "byebye" # type: ignore[arg-type]
2406
2385
2407
2386
# Now it's been reattached, and we can leave the nursery
2408
2387
@@ -2432,9 +2411,8 @@ def abort_fn(_: _core.RaiseCancelT) -> _core.Abort:
2432
2411
await wait_all_tasks_blocked ()
2433
2412
assert task is not None
2434
2413
nursery .cancel_scope .cancel ()
2435
- task .coro .send (
2436
- cast (Any , None ), # type: ignore[misc]
2437
- )
2414
+ # `Argument 1 to "send" of "Coroutine" has incompatible type "None"; expected "Outcome[object]"`
2415
+ task .coro .send (None ) # type: ignore[arg-type]
2438
2416
2439
2417
assert abort_fn_called
2440
2418
0 commit comments