mirror of
https://github.com/python/cpython.git
synced 2025-10-13 18:33:34 +00:00
gh-83791: Raise TypeError for len(memoryview_0d) (#18463)
Changes the behaviour of `len` on a zero-dimensional `memoryview` to raise `TypeError`. Previously, `len` would return `1`.
This commit is contained in:
parent
caed49448d
commit
3d2a46845b
5 changed files with 31 additions and 22 deletions
|
@ -965,8 +965,10 @@ class TestBufferProtocol(unittest.TestCase):
|
|||
self.assertEqual(m.strides, tuple(strides))
|
||||
self.assertEqual(m.suboffsets, tuple(suboffsets))
|
||||
|
||||
n = 1 if ndim == 0 else len(lst)
|
||||
self.assertEqual(len(m), n)
|
||||
if ndim == 0:
|
||||
self.assertRaises(TypeError, len, m)
|
||||
else:
|
||||
self.assertEqual(len(m), len(lst))
|
||||
|
||||
rep = result.tolist() if fmt else result.tobytes()
|
||||
self.assertEqual(rep, lst)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue