From 950f528bf5f620f68c10fc5a35939b716d38ee98 Mon Sep 17 00:00:00 2001 From: Thomas Grainger Date: Fri, 3 Jan 2025 13:16:39 +0000 Subject: [PATCH 1/2] fix create_memory_object_stream not subscriptable at runtime in old anyio versions (#2833) --- pyproject.toml | 2 +- starlette/middleware/base.py | 3 ++- starlette/testclient.py | 22 +++++++++++++--------- 3 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pyproject.toml b/pyproject.toml index 223b6319f..02a3820fc 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -26,7 +26,7 @@ classifiers = [ "Topic :: Internet :: WWW/HTTP", ] dependencies = [ - "anyio>=3.4.0,<5", + "anyio>=3.6.2,<5", "typing_extensions>=3.10.0; python_version < '3.10'", ] diff --git a/starlette/middleware/base.py b/starlette/middleware/base.py index 6e37c6f60..f146984b3 100644 --- a/starlette/middleware/base.py +++ b/starlette/middleware/base.py @@ -172,7 +172,8 @@ async def body_stream() -> typing.AsyncGenerator[bytes, None]: response.raw_headers = message["headers"] return response - send_stream, recv_stream = anyio.create_memory_object_stream[Message]() + streams: anyio.create_memory_object_stream[Message] = anyio.create_memory_object_stream() + send_stream, recv_stream = streams with recv_stream, send_stream, collapse_excgroups(): async with anyio.create_task_group() as task_group: response = await self.dispatch_func(request, call_next) diff --git a/starlette/testclient.py b/starlette/testclient.py index 4f9788feb..fb2ad6e35 100644 --- a/starlette/testclient.py +++ b/starlette/testclient.py @@ -117,8 +117,10 @@ async def _run(self, *, task_status: anyio.abc.TaskStatus[anyio.CancelScope]) -> """ The sub-thread in which the websocket session runs. """ - send_tx, send_rx = anyio.create_memory_object_stream[Message](math.inf) - receive_tx, receive_rx = anyio.create_memory_object_stream[Message](math.inf) + send: anyio.create_memory_object_stream[Message] = anyio.create_memory_object_stream(math.inf) + send_tx, send_rx = send + receive: anyio.create_memory_object_stream[Message] = anyio.create_memory_object_stream(math.inf) + receive_tx, receive_rx = receive with send_tx, send_rx, receive_tx, receive_rx, anyio.CancelScope() as cs: self._receive_tx = receive_tx self._send_rx = send_rx @@ -657,14 +659,16 @@ def __enter__(self) -> TestClient: def reset_portal() -> None: self.portal = None - send1, receive1 = anyio.create_memory_object_stream[ - typing.Union[typing.MutableMapping[str, typing.Any], None] - ](math.inf) - send2, receive2 = anyio.create_memory_object_stream[typing.MutableMapping[str, typing.Any]](math.inf) - for channel in (send1, send2, receive1, receive2): + send: anyio.create_memory_object_stream[typing.MutableMapping[str, typing.Any] | None] = ( + anyio.create_memory_object_stream(math.inf) + ) + receive: anyio.create_memory_object_stream[typing.MutableMapping[str, typing.Any]] = ( + anyio.create_memory_object_stream(math.inf) + ) + for channel in (*send, *receive): stack.callback(channel.close) - self.stream_send = StapledObjectStream(send1, receive1) - self.stream_receive = StapledObjectStream(send2, receive2) + self.stream_send = StapledObjectStream(*send) + self.stream_receive = StapledObjectStream(*receive) self.task = portal.start_task_soon(self.lifespan) portal.call(self.wait_startup) From 0ad90dcbe26e2cf70858d54dcb1ad724977738ae Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 3 Jan 2025 14:24:19 +0100 Subject: [PATCH 2/2] Bump the python-packages group across 1 directory with 7 updates (#2838) Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com> --- requirements.txt | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/requirements.txt b/requirements.txt index 83c34fc9c..88d6fb011 100644 --- a/requirements.txt +++ b/requirements.txt @@ -2,22 +2,22 @@ -e .[full] # Testing -coverage==7.6.1 +coverage==7.6.10 importlib-metadata==8.5.0 -mypy==1.13.0 -ruff==0.8.1 +mypy==1.14.1 +ruff==0.8.5 typing_extensions==4.12.2 types-contextvars==2.4.7.3 -types-PyYAML==6.0.12.20240917 +types-PyYAML==6.0.12.20241230 types-dataclasses==0.6.6 pytest==8.3.4 -trio==0.27.0 +trio==0.28.0 # Documentation black==24.10.0 mkdocs==1.6.1 -mkdocs-material==9.5.47 -mkdocstrings-python==1.12.2 +mkdocs-material==9.5.49 +mkdocstrings-python==1.13.0 # Packaging build==1.2.2.post1