Message284813
# 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 exports of data: object cannot be re-sized"
will be raised after it.
Where exception raised can be far from where unclosed memoryview is leaked.
## 2. bytes(x) constructor is too overloaded.
It has undocumented corner cases. See PEP 467 and #29159
# ML threads
https://mail.python.org/pipermail/python-dev/2016-October/146668.html
https://mail.python.org/pipermail/python-dev/2017-January/147109.html
+1 from: Nathaniel Smith, Alexander Belopolsky, Yury Selivanov
-1 from: Nick Coghlan
Nick proposed put it on separated module, instead of adding it as builtin method.
# First draft patch
bytes-frombuffer.patch is first draft patch. It implements frombuffer to only bytes,
with signature proposed first. Only C-contiguous buffer is supported for now.
frombuffer(byteslike, length=-1, offset=0) method of builtins.type instance
Create a bytes object from bytes-like object.
Examples:
bytes.frombuffer(b'abcd') -> b'abcd'
bytes.frombuffer(b'abcd', 2) -> b'ab'
bytes.frombuffer(b'abcd', 8) -> b'abcd'
bytes.frombuffer(b'abcd', offset=2) -> b'cd'
bytes.frombuffer(b'abcd', 1, 2) -> b'c' |
|
Date |
User |
Action |
Args |
2017-01-06 11:16:17 | methane | set | recipients:
+ methane, ncoghlan, belopolsky, vstinner, Yury.Selivanov |
2017-01-06 11:16:17 | methane | set | messageid: <1483701377.3.0.893514886442.issue29178@psf.upfronthosting.co.za> |
2017-01-06 11:16:17 | methane | link | issue29178 messages |
2017-01-06 11:16:16 | methane | create | |
|