Python 3.8.0 is the latest I can load on Ubuntu 18.04, and I regularly hit the
TypeError because this function is missing. While it can be avoided by
disabling worker usage via config option, that's a bit obscure.
I'm limiting the function definition to the narrow range of affected pythons
because there were other bugs in this area that were worked around, that I don't
fully understand. See the bug report for discussions on why the narrow range,
and related commits working around other bugs.
This could change the size of b, which shouldn’t be done.
If pickle calls readinto() (e.g. on my machine, this happens when the pickled data contains a bytestring >= 2**16 bytes long), it passes a memoryview which doesn’t allow changing its size. Because the size of b is the size of the pickled object and readall() returns all bytes in the stream, containing the bytes for the pickled object + at least one trailing byte, this line would always raise a “ValueError: memoryview assignment: lvalue and rvalue have different structures” exception.
What I suggest instead is to mostly copy-paste the implementation of read() and modify it such that it reads into the provided buffer instead of creating one.