New submission from Eric Wieser <wieser.e...@gmail.com>:
Right now, the behavior is: >>> import numpy as np >>> arr_0d = np.array(42) >>> mem_0d = memoryview(arr_0d) >>> len(mem_0d) 1 >>> mem_0d[0] TypeError: invalid indexing of 0-dim memory It seems bizarre to have this object pretend to be a sequence when you ask for its length, yet not behave like one when you actually try to use this length. I'd suggest cpython should behave like numpy here, and fail: >>> len(arr_0d) TypeError: len() of unsized object Perhaps `TypeError: cannot get length of 0-dim memory` would be more appropriate as a message. --- Wasn't sure how to classify this, feel free to reclassify ---------- components: Interpreter Core messages: 361821 nosy: Eric Wieser, skrah priority: normal severity: normal status: open title: memoryview.__len__ should raise an exception for 0d buffers type: behavior versions: Python 3.5, Python 3.6, Python 3.7, Python 3.8, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue39610> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com