diff --git a/docs/source/reference-core.rst b/docs/source/reference-core.rst index a1d3a83389..9790cd61f9 100644 --- a/docs/source/reference-core.rst +++ b/docs/source/reference-core.rst @@ -1221,7 +1221,7 @@ many cases, you just want to pass objects between different tasks inside a single process, and for that you can use :func:`trio.open_memory_channel`: -.. autofunction:: open_memory_channel +.. autofunction:: open_memory_channel(max_buffer_size) .. note:: If you've used the :mod:`threading` or :mod:`asyncio` modules, you may be familiar with :class:`queue.Queue` or diff --git a/trio/_abc.py b/trio/_abc.py index 300a511fa8..0faec0fdf5 100644 --- a/trio/_abc.py +++ b/trio/_abc.py @@ -484,9 +484,18 @@ async def send_eof(self): """ -T = TypeVar("T") +# The type of object produced by a ReceiveChannel (covariant because +# ReceiveChannel[Derived] can be passed to someone expecting +# ReceiveChannel[Base]) T_co = TypeVar("T_co", covariant=True) + +# The type of object accepted by a SendChannel (contravariant because +# SendChannel[Base] can be passed to someone expecting +# SendChannel[Derived]) T_contra = TypeVar("T_contra", contravariant=True) + +# The type of object produced by a Listener (covariant plus must be +# an AsyncResource) T_resource = TypeVar("T_resource", bound=AsyncResource, covariant=True) @@ -542,7 +551,7 @@ class SendChannel(AsyncResource, Generic[T_contra]): __slots__ = () @abstractmethod - def send_nowait(self, value: T_contra) -> None: + def send_nowait(self, value): """Attempt to send an object through the channel, without blocking. Args: @@ -560,7 +569,7 @@ def send_nowait(self, value: T_contra) -> None: """ @abstractmethod - async def send(self, value: T_contra) -> None: + async def send(self, value): """Attempt to send an object through the channel, blocking if necessary. Args: @@ -577,7 +586,7 @@ async def send(self, value: T_contra) -> None: """ @abstractmethod - def clone(self: T) -> T: + def clone(self): """Clone this send channel object. This returns a new :class:`SendChannel` object, which acts as a @@ -625,7 +634,7 @@ class ReceiveChannel(AsyncResource, Generic[T_co]): __slots__ = () @abstractmethod - def receive_nowait(self) -> T_co: + def receive_nowait(self): """Attempt to receive an incoming object, without blocking. Returns: @@ -644,7 +653,7 @@ def receive_nowait(self) -> T_co: """ @abstractmethod - async def receive(self) -> T_co: + async def receive(self): """Attempt to receive an incoming object, blocking if necessary. It's legal for multiple tasks to call :meth:`receive` at the same @@ -665,7 +674,7 @@ async def receive(self) -> T_co: """ @abstractmethod - def clone(self: T) -> T: + def clone(self): """Clone this receive channel object. This returns a new :class:`ReceiveChannel` object, which acts as a