Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix create_memory_object_stream not subscriptable at runtime in old anyio versions #2833

Merged
merged 2 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
]

Expand Down
3 changes: 2 additions & 1 deletion starlette/middleware/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
22 changes: 13 additions & 9 deletions starlette/testclient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
Loading