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

asyncio.BaseProactorEventLoop feeds bytearray objects to the Protocol.data_received callback, contradicting docs #123496

Closed
jonathanslenders opened this issue Aug 30, 2024 · 3 comments
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error

Comments

@jonathanslenders
Copy link

jonathanslenders commented Aug 30, 2024

Bug report

Bug description:

The documentation says: https://docs.python.org/3/library/asyncio-protocol.html#asyncio.Protocol.data_received :

Called when some data is received. data is a non-empty bytes object containing the incoming data.

So, it says it should be a bytes object. However:

So, there we get a bytearray object.

This conflicts with the current type hints from typeshed: https://github.com/python/typeshed/blob/main/stdlib/asyncio/protocols.pyi#L14 as well as with the docs.

Is this intentional or not?

The patch is simple:

--- a/Lib/asyncio/proact
+++ b/Lib/asyncio/proactor_events.py
@@ -271,7 +271,7 @@ def _data_received(self, data, length):
                                   'call failed.')
                 return
         else:
-            self._protocol.data_received(data)
+            self._protocol.data_received(bytes(data))

     def _loop_reading(s
         length = -1

Related typeshed issue: python/typeshed#12606

CPython versions tested on:

3.13

Operating systems tested on:

Windows

@jonathanslenders
Copy link
Author

Actually, maybe it's a duplicate of: #99941

@jonathanslenders
Copy link
Author

Closing this. Apparently it was fixed in v3.12.0a thanks to 1bb68ba

@github-project-automation github-project-automation bot moved this from Todo to Done in asyncio Aug 30, 2024
@agronholm
Copy link
Contributor

I can still reproduce this with 3.12.5.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-asyncio type-bug An unexpected behavior, bug, or error
Projects
Status: Done
Development

No branches or pull requests

3 participants