This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author serhiy.storchaka
Recipients Yury.Selivanov, belopolsky, methane, ncoghlan, serhiy.storchaka, vstinner, yselivanov
Date 2017-01-06.17:08:06
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1483722486.96.0.947335023496.issue29178@psf.upfronthosting.co.za>
In-reply-to
Content
Count me as -1 too.

This is just a two-liner:

    with memoryview(bytelike) as m:
        bs = bytes(m[start:end])

In most cases, when all content is used, the bytes constructor works fine.

    bs = bytes(bytelike)

This works not just with bytes, but with bytearray and most other bytes-like arrays. With frombuffer() you need to add a new class method to all these classes.

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

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.

There is also a problem with returned type for subclasses (this is always a problem for alternate constructors). Should B.frombuffer() where B is a bytes subclass return an instance of bytes or B? If it always returns a bytes object, we need to use a constructor for subclasses, if it returns an instance of a subclass, how can it be implemented efficiently?
History
Date User Action Args
2017-01-06 17:08:07serhiy.storchakasetrecipients: + serhiy.storchaka, ncoghlan, belopolsky, vstinner, methane, Yury.Selivanov, yselivanov
2017-01-06 17:08:06serhiy.storchakasetmessageid: <1483722486.96.0.947335023496.issue29178@psf.upfronthosting.co.za>
2017-01-06 17:08:06serhiy.storchakalinkissue29178 messages
2017-01-06 17:08:06serhiy.storchakacreate