-
-
Notifications
You must be signed in to change notification settings - Fork 33k
Description
Bug report
Bug description:
When using any of the write or sendto methods in the asyncio library with anything that is not an instance of bytes, bytearray or memoryview, one gets the error message "data argument must be a bytes-like object". This is even true if one does pass a bytes-like object.
The reason is that the code checks for exactly those three types. But there are many other types which are bytes-like. Until now it is only a documentation bug: one could just fix the error message.
However, it is also a real bug, because if you hand in a non-contiguous memory view to those methods, they will not complain, however they will fail, and that in a not-so-nice way, as the methods will happily put the data into a buffer to be sent out later, and at this later time it will fail.
Unfortunately I am not aware of a good test whether something is bytes-like. The test should be: does it pass well with the PyArg_Parse y* format type, as this is, according to the documentation, the recommended way to accept binary data, and also what the underlying functions in asyncio do.
CPython versions tested on:
3.11
Operating systems tested on:
No response
Linked PRs
- gh-138703: remove unnecessary and buggy type checks in asyncio #138737
- gh-138703: clarify data buffer requirement of
asyncio.StreamWriter.write
#139564 - [3.14] gh-138703: clarify data buffer requirement of
asyncio.StreamWriter.write
(GH-139564) #139570 - [3.13] gh-138703: clarify data buffer requirement of
asyncio.StreamWriter.write
(GH-139564) #139571
Metadata
Metadata
Assignees
Labels
Projects
Status
Status