[issue29178] Adding bytes.frombuffer(byteslike) constructor

2021-03-20 Thread Gregory P. Smith
Change by Gregory P. Smith : -- stage: -> patch review versions: -Python 3.8, Python 3.9 ___ Python tracker ___ ___

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2021-03-20 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: I am more warm to this feature now (+0). Not because it would allow to write some code shorter, but because it can be in line with other type-strict alternate constructors, like int.fromnumber() and int.parse(). But questions about parameters and

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2021-03-20 Thread Eryk Sun
Change by Eryk Sun : -- versions: +Python 3.10, Python 3.8, Python 3.9 -Python 3.7 ___ Python tracker ___ ___ Python-bugs-list

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-04-12 Thread INADA Naoki
INADA Naoki added the comment: FYI, Tornado 4.5b switched buffer implementation from deque-of-bytes to bytearray like asyncio. I sent PR for fixing "unreleased memoryview". https://github.com/tornadoweb/tornado/pull/2008 This is common pitfall when implementing buffer. --

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-07 Thread Nick Coghlan
Nick Coghlan added the comment: The complexity you're hitting here is the main reason I'm a fan of creating a dedicated library for dealing with these problems, rather than trying to handle them directly on the builtins. Given a bufferlib module, for example, you could have a higher level API

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-07 Thread INADA Naoki
INADA Naoki added the comment: You're right! How difficult working with memoryview! > The memoryview constructor could take start, stop, and step keyword-only > arguments to avoid having to immediately slice a new view. Maybe, memoryview.to_bytes() is better place to add such options.

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-07 Thread Eryk Sun
Eryk Sun added the comment: Isn't the proposed workaround also relying on CPython reference counting to immediately deallocate the sliced view? It fails if I keep a reference to the sliced view: byteslike = bytearray(b'abc') with memoryview(byteslike) as m1: m2 = m1[1:]

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-07 Thread INADA Naoki
INADA Naoki added the comment: > I'm -1 if the intention is about easiness and efficiency. Do you +1 when adding it to stdlib (say "bufferlib")? > Creating a memoryview is not cheap enough in such a case. Actually speaking, it's 5 calls + 2 temporary memoriview. 1. creating memoryview. 2.

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-07 Thread Xiang Zhang
Xiang Zhang added the comment: I'm -1 if the intention is about easiness and efficiency. I think a new API is usually added due to functional defect not performance defect. We get a way here though the performance seems not ideal, according to INADA's mail. I think we should first check if

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: > Which virtually no one follows :( Sad. But adding bytes.frombuffer() wouldn't make it magically used. If you are aware of the problem, you can use the above two-liner as well as bytes.frombuffer(). You even can use it in the current code with older Python

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-06 Thread Yury Selivanov
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()

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-06 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: 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

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-06 Thread Yury Selivanov
Yury Selivanov added the comment: I've added a couple of review comments. Also, it looks like you can count Antoine Pitrou as +1 too. Two questions: 1. length or count? Need to look through builtins/stdlib and see what is more common in CPython. 2. Maybe we should make length/count and

[issue29178] Adding bytes.frombuffer(byteslike) constructor

2017-01-06 Thread INADA Naoki
New submission from INADA Naoki: # Summary ## 1. Making bytes from slice of bytearray easy and efficient. bs = bytes(memoryview(bytelike)[start:end]) works fine on CPython, but it will cause issue on PyPy. Since memoryview is not closed explicitly, exception like "BufferError: Existing