[issue29178] Adding bytes.frombuffer(byteslike) constructor

Yury Selivanov report at bugs.python.org
Fri Jan 6 12:13:33 EST 2017


Yury Selivanov added the comment:

> This is just a two-liner:
>
>    with memoryview(bytelike) as m:
>        bs = bytes(m[start:end])

Which virtually no one follows :(


> Adding new method to builtin type has high bar. I doubts that there are enough use cases in which bytes.frombuffer() has an advantage.

Any protocol parsing code has a lot of slicing.

> The signature of bytes.frombuffer() looks questionable. Why length and offset instead of start and stop indices as in slices? Why length is first and offset is last? This contradicts the interface of Python 2 buffer(), socket.sendfile(), os.sendfile(), etc.

I propose to make both arguments keyword-only.

> There is also a problem with returned type for subclasses (this is always a problem for alternate constructors).

Good point. How do we usually solve this in CPython?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29178>
_______________________________________


More information about the Python-bugs-list mailing list