11from collections import deque , OrderedDict
22from math import inf
3+ from typing import NamedTuple
34
45import attr
56from outcome import Error , Value
67
7- from .abc import SendChannel , ReceiveChannel , Channel
8+ from .abc import SendChannel , ReceiveChannel
89from ._util import generic_function , NoPublicConstructor
910
1011import trio
1112from ._core import enable_ki_protection
1213
1314
15+ class MemoryChannelPair (NamedTuple ):
16+ """Named tuple of send/receive memory channels"""
17+
18+ send_channel : "MemorySendChannel"
19+ receive_channel : "MemoryReceiveChannel"
20+
21+
1422@generic_function
1523def open_memory_channel (max_buffer_size ):
1624 """Open a channel for passing objects between tasks within a process.
@@ -40,9 +48,8 @@ def open_memory_channel(max_buffer_size):
4048 see :ref:`channel-buffering` for more details. If in doubt, use 0.
4149
4250 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.
4653
4754 In addition to the standard channel methods, all memory channel objects
4855 provide a ``statistics()`` method, which returns an object with the
@@ -69,7 +76,7 @@ def open_memory_channel(max_buffer_size):
6976 if max_buffer_size < 0 :
7077 raise ValueError ("max_buffer_size must be >= 0" )
7178 state = MemoryChannelState (max_buffer_size )
72- return (
79+ return MemoryChannelPair (
7380 MemorySendChannel ._create (state ),
7481 MemoryReceiveChannel ._create (state ),
7582 )
0 commit comments