A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://mail.python.org/pipermail/python-dev/2017-January/147114.html below:

[Python-Dev] Adding bytes.frombuffer() constructor to PEP 467

[Python-Dev] Adding bytes.frombuffer() constructor to PEP 467 [Python-Dev] Adding bytes.frombuffer() constructor to PEP 467Yury Selivanov yselivanov.ml at gmail.com
Thu Jan 5 20:28:26 EST 2017
On 2017-01-05 7:11 PM, INADA Naoki wrote:
>> bytes.frombuffer(x) is bytes(memoryview(x)) or memoryview(x).tobytes().
>>
> There is pitfall: memoryview should be closed.
> So b = bytes.frombuffer(x) is:
>
> with memoryview(x) as m:
>      b = bytes(m)
>      # or b = m.tobytes()


Thinking more about this, and after looking at my own code in asyncpg 
and uvloop, I'm now in favor of adding bytes.frombuffer() with the 
proposed signature: ``bytes.frombuffer(byteslike, length=-1, offset=0)``

Inada-san is right, the memoryview should be explicitly released, but 
few do that. Instead, a lot of people simply rely on CPython refcounting 
semantics, which will cause the temporary memoryview be GCed asap.  That 
won't work so flawlessly in PyPy and will cause hard to understand bugs.

Yury
More information about the Python-Dev mailing list

RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4