Swap `open_channel_from()` to yield `(chan, first)`

Deliver `(LinkedTaskChannel, Any)` instead of the prior `(first, chan)`
order from `open_channel_from()` to match the type annotation and be
consistent with `trio.open_*_channel()` style where the channel obj
comes first.

- flip `yield first, chan` -> `yield chan, first`
- update type annotation + docstring to match
- swap all unpack sites in tests and examples

(this patch was generated in some part by [`claude-code`][claude-code-gh])
[claude-code-gh]: https://github.com/anthropics/claude-code
ns_aware
Gud Boi 2026-03-12 16:32:44 -04:00
parent e89fe03da7
commit b3ce5ab4f6
6 changed files with 12 additions and 13 deletions

View File

@ -59,7 +59,7 @@ async def trio_ctx(
to_asyncio.open_channel_from( to_asyncio.open_channel_from(
bp_then_error, bp_then_error,
# raise_after_bp=not bp_before_started, # raise_after_bp=not bp_before_started,
) as (first, chan), ) as (chan, first),
trio.open_nursery() as tn, trio.open_nursery() as tn,
): ):

View File

@ -33,7 +33,7 @@ async def trio_to_aio_echo_server(
# message. # message.
async with tractor.to_asyncio.open_channel_from( async with tractor.to_asyncio.open_channel_from(
aio_echo_server, aio_echo_server,
) as (first, chan): ) as (chan, first):
assert first == 'start' assert first == 'start'
await ctx.started(first) await ctx.started(first)

View File

@ -68,7 +68,7 @@ async def wrapper_mngr(
else: else:
async with tractor.to_asyncio.open_channel_from( async with tractor.to_asyncio.open_channel_from(
aio_streamer, aio_streamer,
) as (first, from_aio): ) as (from_aio, first):
assert not first assert not first
# cache it so next task uses broadcast receiver # cache it so next task uses broadcast receiver

View File

@ -237,7 +237,7 @@ async def trio_ctx(
trio.open_nursery() as tn, trio.open_nursery() as tn,
tractor.to_asyncio.open_channel_from( tractor.to_asyncio.open_channel_from(
sleep_and_err, sleep_and_err,
) as (first, chan), ) as (chan, first),
): ):
assert first == 'start' assert first == 'start'
@ -474,7 +474,7 @@ async def stream_from_aio(
trio_exit_early trio_exit_early
)) ))
) as (first, chan): ) as (chan, first):
assert first is True assert first is True
@ -768,8 +768,8 @@ async def trio_to_aio_echo_server(
async with to_asyncio.open_channel_from( async with to_asyncio.open_channel_from(
aio_echo_server, aio_echo_server,
) as ( ) as (
first, # value from `chan.started_nowait()` above
chan, chan,
first, # value from `chan.started_nowait()` above
): ):
assert first == 'start' assert first == 'start'

View File

@ -49,7 +49,7 @@ def test_infected_root_actor(
), ),
to_asyncio.open_channel_from( to_asyncio.open_channel_from(
aio_echo_server, aio_echo_server,
) as (first, chan), ) as (chan, first),
): ):
assert first == 'start' assert first == 'start'
@ -173,7 +173,7 @@ def test_trio_prestarted_task_bubbles(
sync_and_err, sync_and_err,
ev=aio_ev, ev=aio_ev,
) )
) as (first, chan), ) as (chan, first),
): ):
for i in range(5): for i in range(5):

View File

@ -1299,15 +1299,15 @@ async def open_channel_from(
**target_kwargs, **target_kwargs,
) -> AsyncIterator[ ) -> AsyncIterator[
tuple[Any, LinkedTaskChannel] tuple[LinkedTaskChannel, Any]
]: ]:
''' '''
Start an `asyncio.Task` as `target()` and open an Start an `asyncio.Task` as `target()` and open an
inter-loop (linked) channel for streaming between inter-loop (linked) channel for streaming between
it and the current `trio.Task`. it and the current `trio.Task`.
A pair `(Any, chan: LinkedTaskChannel)` is delivered A pair `(chan: LinkedTaskChannel, Any)` is delivered
to the caller where the 1st element is the value to the caller where the 2nd element is the value
provided by the `asyncio.Task`'s unblocking call provided by the `asyncio.Task`'s unblocking call
to `chan.started_nowait()`. to `chan.started_nowait()`.
@ -1333,8 +1333,7 @@ async def open_channel_from(
first = await chan.receive() first = await chan.receive()
# deliver stream handle upward # deliver stream handle upward
yield first, chan yield chan, first
# ^TODO! swap these!!
except trio.Cancelled as taskc: except trio.Cancelled as taskc:
if cs.cancel_called: if cs.cancel_called:
if isinstance(chan._trio_to_raise, AsyncioCancelled): if isinstance(chan._trio_to_raise, AsyncioCancelled):