Issue #22668: Ensure that format strings survive slicing after casting.

This commit is contained in:
Stefan Krah 2015-01-29 14:27:23 +01:00
parent 2934262fd3
commit fa5d6a5ff3
3 changed files with 73 additions and 6 deletions

View file

@ -360,6 +360,25 @@ class AbstractMemoryTests:
self.assertEqual(list(reversed(m)), aslist)
self.assertEqual(list(reversed(m)), list(m[::-1]))
def test_issue22668(self):
m = memoryview(bytes(range(8)))
b = m.cast('H')
c = b[0:2]
d = memoryview(b)
del b
self.assertEqual(c[0], 256)
self.assertEqual(d[0], 256)
self.assertEqual(c.format, "H")
self.assertEqual(d.format, "H")
_ = m.cast('I')
self.assertEqual(c[0], 256)
self.assertEqual(d[0], 256)
self.assertEqual(c.format, "H")
self.assertEqual(d.format, "H")
# Variations on source objects for the buffer: bytes-like objects, then arrays
# with itemsize > 1.