summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_buffer.py
diff options
context:
space:
mode:
authorEric Wieser <wieser.eric@gmail.com>2023-04-22 16:32:47 (GMT)
committerGitHub <noreply@github.com>2023-04-22 16:32:47 (GMT)
commit3d2a46845b67407e2436d910b2e1740c34f4f10d (patch)
tree607d43aa0a30a293fcffc2623453cc7787687edd /Lib/test/test_buffer.py
parentcaed49448d195565940caf198cf0edda65ee5679 (diff)
downloadcpython-3d2a46845b67407e2436d910b2e1740c34f4f10d.zip
cpython-3d2a46845b67407e2436d910b2e1740c34f4f10d.tar.gz
cpython-3d2a46845b67407e2436d910b2e1740c34f4f10d.tar.bz2
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`.
Diffstat (limited to 'Lib/test/test_buffer.py')
-rw-r--r--Lib/test/test_buffer.py6
1 files changed, 4 insertions, 2 deletions
diff --git a/Lib/test/test_buffer.py b/Lib/test/test_buffer.py
index 8ac3b7e..098d2d9 100644
--- a/Lib/test/test_buffer.py
+++ b/Lib/test/test_buffer.py
@@ -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)