@@ -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,7 +19,7 @@
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):
@@ -27,7 +27,7 @@
Loading
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
Files Coverage
trio 99.64%
Project Totals (114 files) 99.64%
pypy_nightly_py3.6
Build #4469.2 -
TRAVIS_OS_NAME=linux
linux-3.6.1
Build #4469.5 -
3.6.1=.6.1
TRAVIS_OS_NAME=linux
linux-3.7-dev
Build #4469.7 -
TRAVIS_OS_NAME=linux
3.7-dev=.7-dev
linux-3.6-dev
Build #4469.6 -
TRAVIS_OS_NAME=linux
3.6-dev=.6-dev
macOS (3.9.0-rc.2)
Build #328279221 -
Windows (3.8, x64, with non-IFS LSP)
Build #328279221 -
FreeBSD 12.1-RELEASE, full VM
Build #4469.3 -
TRAVIS_OS_NAME=
Fedora 32, full VM
Build #4469.4 -
TRAVIS_OS_NAME=
linux-3.9-dev
Build #4469.9 -
3.9-dev=.9-dev
TRAVIS_OS_NAME=linux
linux-3.8-dev
Build #4469.8 -
3.8-dev=.8-dev
TRAVIS_OS_NAME=linux
Ubuntu (3.8)
Build #328279221 -
Ubuntu (3.7)
Build #328279221 -
linux-3.9-dev
Build #4468.9 -
3.9-dev=.9-dev
TRAVIS_OS_NAME=linux
Ubuntu (3.6)
Build #328279221 -
Windows (3.8, x64)
Build #328279221 -
Ubuntu (3.9.0-rc.2)
Build #328279221 -
Windows (3.7, x64)
Build #328279221 -
macOS (3.6)
Build #328279221 -
Windows (3.8, x86)
Build #328279221 -
Windows (3.6, x86)
Build #328279221 -
Windows (3.8, x64, with Komodia LSP)
Build #328279221 -
Windows (3.7, x86)
Build #328279221 -
Windows (3.6, x64)
Build #328279221 -
Windows (3.8, x64, with IFS LSP)
Build #328279221 -
Windows (3.9.0-rc.2, x86)
Build #328279221 -
Alpine
Build #328279221 -
macOS (3.8)
Build #328279221 -
Windows (3.9.0-rc.2, x64)
Build #328279221 -
linux-pypy3.6-7.2.0
Build #4469.1 -
TRAVIS_OS_NAME=linux
pypy3.6-7.2.0=.6-7.2.0
macOS (3.7)
Build #328279221 -

No yaml found.

Create your codecov.yml to customize your Codecov experience

Sunburst
The inner-most circle is the entire project, moving away from the center are folders then, finally, a single file. The size and color of each slice is representing the number of statements and the coverage, respectively.
Icicle
The top section represents the entire project. Proceeding with folders and finally individual files. The size and color of each slice is representing the number of statements and the coverage, respectively.
Grid
Each block represents a single file in the project. The size and color of each block is represented by the number of statements and the coverage, respectively.
Loading