Message284954
| Author |
eryksun |
| Recipients |
Yury.Selivanov, belopolsky, eryksun, methane, ncoghlan, serhiy.storchaka, vstinner, xiang.zhang, yselivanov |
| Date |
2017年01月08日.03:22:43 |
| SpamBayes Score |
-1.0 |
| Marked as misclassified |
Yes |
| Message-id |
<1483845763.9.0.721185667787.issue29178@psf.upfronthosting.co.za> |
| In-reply-to |
| Content |
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:]
bs = bytes(m2)
>>> byteslike += b'd'
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
BufferError: Existing exports of data: object cannot be re-sized
It seems to me that it should be written as follows:
with memoryview(byteslike) as m1:
with m1[1:] as m2:
bs = bytes(m2)
>>> byteslike += b'd'
>>> byteslike
bytearray(b'abcd')
The memoryview constructor could take start, stop, and step keyword-only arguments to avoid having to immediately slice a new view. |
|