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

Convert bytearray to bytes in StreamProtocol.receive() #777

Merged
merged 3 commits into from
Sep 1, 2024
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
3 changes: 3 additions & 0 deletions docs/versionhistory.rst
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ This library adheres to `Semantic Versioning 2.0 <http://semver.org/>`_.
(`#696 <https://github.com/agronholm/anyio/issues/696>`_)
- Fixed ``TaskInfo.has_pending_cancellation()`` on asyncio not respecting shielded
scopes (`#771 <https://github.com/agronholm/anyio/issues/771>`_; PR by @gschaffner)
- Fixed ``SocketStream.receive()`` returning ``bytearray`` instead of ``bytes`` when
using asyncio with ``ProactorEventLoop`` (Windows)
(`#776 <https://github.com/agronholm/anyio/issues/776>`_)
- Fixed quitting the debugger in a pytest test session while in an active task group
failing the test instead of exiting the test session (because the exit exception
arrives in an exception group)
Expand Down
3 changes: 2 additions & 1 deletion src/anyio/_backends/_asyncio.py
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,8 @@ def connection_lost(self, exc: Exception | None) -> None:
self.write_event.set()

def data_received(self, data: bytes) -> None:
self.read_queue.append(data)
# ProactorEventloop sometimes sends bytearray instead of bytes
self.read_queue.append(bytes(data))
self.read_event.set()

def eof_received(self) -> bool | None:
Expand Down
4 changes: 3 additions & 1 deletion tests/test_sockets.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,9 @@ def serve() -> None:
thread.start()
response = b""
while len(response) < len(buffer):
response += await stream.receive()
chunk = await stream.receive()
assert isinstance(chunk, bytes)
response += chunk

thread.join()
assert response == buffer
Expand Down
Loading