typeshed icon indicating copy to clipboard operation
typeshed copied to clipboard

`asyncio.Protocol.data_received` should also accept `bytearray` alongside `bytes`

Open jonathanslenders opened this issue 1 year ago • 2 comments

Asyncio's _ProactorReadPipeTransport can also feed bytearray objects in the data_received callback from asyncio.Protocol.

  • First, self._data is a bytearray here: https://github.com/python/cpython/blob/f8a736b8e14ab839e1193cb1d3955b61c316d048/Lib/asyncio/proactor_events.py#L191
  • This gets passed to `self._data_received here: https://github.com/python/cpython/blob/f8a736b8e14ab839e1193cb1d3955b61c316d048/Lib/asyncio/proactor_events.py#L230
  • The passed into Protocol.data_received here: https://github.com/python/cpython/blob/f8a736b8e14ab839e1193cb1d3955b61c316d048/Lib/asyncio/proactor_events.py#L274

Shall I make a PR with a fix for this?

Related cpython issue: https://github.com/python/cpython/issues/123496 - I'm not sure whether or not it should be fixed in the stdlib instead.

jonathanslenders avatar Aug 30 '24 10:08 jonathanslenders

It looks like it was fixed in cpython v3.12.0a4 thanks to this commit: https://github.com/python/cpython/commit/1bb68ba6d9de6bb7f00aee11d135123163f15887

What do we do in this case? Put an if sys.version_info < (3, 12): in place?

jonathanslenders avatar Aug 30 '24 10:08 jonathanslenders

Possibly add a version and a platform check. But considering that this is simply a (fixed) bug in the stdlib, I'd be fine with doing nothing.

srittau avatar Aug 30 '24 10:08 srittau