Skip to content

Commit

Permalink
Convert bytearray to bytes in StreamProtocol.receive() (agronholm#777)
Browse files Browse the repository at this point in the history
  • Loading branch information
agronholm authored Sep 1, 2024
1 parent 8a5b346 commit bc962ef
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 2 deletions.
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

0 comments on commit bc962ef

Please sign in to comment.