#1771 open_memory_channel(): return a named tuple

Open John Belmonte belm0
Coverage Reach
_core/tests/test_run.py _core/tests/test_multierror.py _core/tests/test_ki.py _core/tests/test_guest_mode.py _core/tests/test_io.py _core/tests/test_asyncgen.py _core/tests/test_instrumentation.py _core/tests/test_parking_lot.py _core/tests/test_windows.py _core/tests/test_mock_clock.py _core/tests/test_unbounded_queue.py _core/tests/test_thread_cache.py _core/tests/test_local.py _core/tests/tutil.py _core/tests/test_multierror_scripts/simple_excepthook.py _core/tests/test_multierror_scripts/custom_excepthook.py _core/tests/test_multierror_scripts/simple_excepthook_partial.py _core/tests/test_multierror_scripts/apport_excepthook.py _core/tests/test_multierror_scripts/simple_excepthook_IPython.py _core/tests/test_multierror_scripts/_common.py _core/tests/conftest.py _core/tests/test_tutil.py _core/tests/test_util.py _core/_run.py _core/_io_windows.py _core/_multierror.py _core/_io_kqueue.py _core/_io_epoll.py _core/_windows_cffi.py _core/_ki.py _core/_mock_clock.py _core/_asyncgens.py _core/_entry_queue.py _core/_wakeup_socketpair.py _core/_local.py _core/_unbounded_queue.py _core/_instrumentation.py _core/_parking_lot.py _core/_thread_cache.py _core/_traps.py _core/_io_common.py _core/__init__.py _core/_exceptions.py tests/test_ssl.py tests/test_socket.py tests/test_testing.py tests/test_sync.py tests/test_threads.py tests/test_subprocess.py tests/test_highlevel_open_tcp_stream.py tests/test_channel.py tests/test_highlevel_open_tcp_listeners.py tests/test_highlevel_socket.py tests/test_unix_pipes.py tests/test_path.py tests/test_wait_for_object.py tests/test_deprecate.py tests/test_signals.py tests/test_file_io.py tests/test_util.py tests/test_highlevel_serve_listeners.py tests/test_windows_pipes.py tests/test_exports.py tests/test_highlevel_generic.py tests/test_highlevel_ssl_helpers.py tests/test_timeouts.py tests/test_highlevel_open_unix_stream.py tests/tools/test_gen_exports.py tests/test_scheduler_determinism.py tests/test_abc.py tests/conftest.py tests/module_with_deprecations.py testing/_check_streams.py testing/_memory_streams.py testing/_sequencer.py testing/_checkpoints.py testing/_trio_test.py testing/_network.py testing/__init__.py _socket.py _sync.py _subprocess.py _ssl.py _channel.py _util.py _path.py _highlevel_socket.py _threads.py _subprocess_platform/waitid.py _subprocess_platform/__init__.py _subprocess_platform/kqueue.py _subprocess_platform/windows.py _unix_pipes.py _abc.py _tools/gen_exports.py _windows_pipes.py _highlevel_open_tcp_stream.py _deprecate.py _signals.py _file_io.py _highlevel_open_tcp_listeners.py socket.py __init__.py _timeouts.py _highlevel_serve_listeners.py _highlevel_generic.py _wait_for_object.py _highlevel_open_unix_stream.py _highlevel_ssl_helpers.py lowlevel.py to_thread.py from_thread.py abc.py _version.py

No flags found

Use flags to group coverage reports by test type, project and/or folders.
Then setup custom commit statuses and notifications for each flag.

e.g., #unittest #integration

#production #enterprise

#frontend #backend

Learn more about Codecov Flags here.


@@ -1,16 +1,24 @@
Loading
1 1
from collections import deque, OrderedDict
2 2
from math import inf
3 +
from typing import NamedTuple
3 4
4 5
import attr
5 6
from outcome import Error, Value
6 7
7 -
from .abc import SendChannel, ReceiveChannel, Channel
8 +
from .abc import SendChannel, ReceiveChannel
8 9
from ._util import generic_function, NoPublicConstructor
9 10
10 11
import trio
11 12
from ._core import enable_ki_protection
12 13
13 14
15 +
class MemoryChannelPair(NamedTuple):
16 +
    """Named tuple of send/receive memory channels"""
17 +
18 +
    send_channel: "MemorySendChannel"
19 +
    receive_channel: "MemoryReceiveChannel"
20 +
21 +
14 22
@generic_function
15 23
def open_memory_channel(max_buffer_size):
16 24
    """Open a channel for passing objects between tasks within a process.
@@ -40,9 +48,8 @@
Loading
40 48
        see :ref:`channel-buffering` for more details. If in doubt, use 0.
41 49
42 50
    Returns:
43 -
      A pair ``(send_channel, receive_channel)``. If you have
44 -
      trouble remembering which order these go in, remember: data
45 -
      flows from left → right.
51 +
      A named tuple ``(send_channel, receive_channel)``.  The tuple ordering is
52 +
      intended to match the image of data flowing from left → right.
46 53
47 54
    In addition to the standard channel methods, all memory channel objects
48 55
    provide a ``statistics()`` method, which returns an object with the
@@ -69,7 +76,7 @@
Loading
69 76
    if max_buffer_size < 0:
70 77
        raise ValueError("max_buffer_size must be >= 0")
71 78
    state = MemoryChannelState(max_buffer_size)
72 -
    return (
79 +
    return MemoryChannelPair(
73 80
        MemorySendChannel._create(state),
74 81
        MemoryReceiveChannel._create(state),
75 82
    )

@@ -350,3 +350,8 @@
Loading
350 350
            assert await r.receive() == 1
351 351
    with pytest.raises(trio.WouldBlock):
352 352
        r.receive_nowait()
353 +
354 +
355 +
def test_named_tuple():
356 +
    pair = open_memory_channel(0)
357 +
    assert pair.send_channel, pair.receive_channel == pair

@@ -19,15 +19,15 @@
Loading
19 19
    async def connect(self):
20 20
        assert not self.closed
21 21
        client, server = memory_stream_pair()
22 -
        await self.queued_streams[0].send(server)
22 +
        await self.queued_streams.send_channel.send(server)
23 23
        return client
24 24
25 25
    async def accept(self):
26 26
        await trio.lowlevel.checkpoint()
27 27
        assert not self.closed
28 28
        if self.accept_hook is not None:
29 29
            await self.accept_hook()
30 -
        stream = await self.queued_streams[1].receive()
30 +
        stream = await self.queued_streams.receive_channel.receive()
31 31
        self.accepted_streams.append(stream)
32 32
        return stream
33 33

Everything is accounted for!

No changes detected that need to be reviewed.
What changes does Codecov check for?
Lines, not adjusted in diff, that have changed coverage data.
Files that introduced coverage data that had none before.
Files that have missing coverage data that once were tracked.
Files Coverage
trio +<.01% 99.64%
Project Totals (114 files) 99.64%
Loading