[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-09-07 Thread Stefan Krah
Stefan Krah added the comment: list() has to *interpret* the endianness to display it. The endianness of the *native* format does not matter. The endianness of an explicit format matters, since list has to be able to convert non-native formats. I suggest to look at XND, which is a memoryview

[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-09-07 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: It is surprising the endianess of byte matters. -- ___ Python tracker ___ ___ Python-bugs-list

[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-09-07 Thread Stefan Krah
Stefan Krah added the comment: memoryview can store anything, but only access and display the native format. The reason is that conversions in the manner of the struct module are very expensive. You can construct all sorts of formats that memoryview cannot handle: >>> x = array(1, "c") >>> x

[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-09-07 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: But iterating it raises different type of exception, wish obscure message. >>> import ctypes >>> mem_0d = memoryview(ctypes.c_uint8(42)) >>> list(mem_0d) Traceback (most recent call last): File "", line 1, in NotImplementedError: memoryview: unsupported

[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-03-02 Thread Eric Wieser
Eric Wieser added the comment: Thanks for pointing out the docs reference, I updated the patch to reword that section. There's a sentence right before the one you draw attention to which to me reads as another argument to change this: > ``len(view)`` is equal to the length of

[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-02-11 Thread Stefan Krah
Stefan Krah added the comment: The change looks reasonable, but unfortunately this is a long-standing behavior that originates from before the Python-3.3 memoryview rewrite. It is also present in 2.7 (the previous implementation) and documented in 3.3:

[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-02-11 Thread Eric Wieser
Change by Eric Wieser : -- keywords: +patch pull_requests: +17836 stage: -> patch review pull_request: https://github.com/python/cpython/pull/18463 ___ Python tracker ___

[issue39610] memoryview.__len__ should raise an exception for 0d buffers

2020-02-11 Thread Eric Wieser
New submission from Eric Wieser : 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