This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients Eric.Wieser, amaury.forgeotdarc, belopolsky, meador.inge, skrah, teoliphant, terry.reedy
Date 2019-04-14.20:04:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1555272267.66.0.396391978203.issue32782@roundup.psfhosted.org>
In-reply-to
Content
This issue is about the itemsize attribute of instances of the built-in memoryview class.  Ctypes in only involved in providing format information.  Hence the nosy additions.

On Win10 with 3.8, ctypes has no uint attributes.  Using 'c_int32' instead, I see the same behavior (itemsize 0 for empty structure).

About itemsize, https://www.python.org/dev/peps/pep-3118/ says

"This is a storage for the itemsize (in bytes) of each element of the shared memory. It is technically un-necessary as it can be obtained using PyBuffer_SizeFromFormat, however an exporter may know this information without parsing the format string and it is necessary to know the itemsize for proper interpretation of striding. Therefore, storing it is more convenient and faster."

The first line could be seen as implying that itemsize is undefined if there are no items (and as justifying numbytes/numitems otherwise).  The 0 return could be seen as equivalent to a None return from a python-coded function.  If so, it is not a bug, and there might be code that would break if it is changed.

On the other hand, the next lines imply that itemsize is *usually*, though not necessarily, a cache for PyBuffer_SizeFromFormat.  This could be seen as implying that in the absence of other information, the itemsize should be calculated from the format, making 0 a bug.
History
Date User Action Args
2019-04-14 20:04:27terry.reedysetrecipients: + terry.reedy, teoliphant, amaury.forgeotdarc, belopolsky, skrah, meador.inge, Eric.Wieser
2019-04-14 20:04:27terry.reedysetmessageid: <1555272267.66.0.396391978203.issue32782@roundup.psfhosted.org>
2019-04-14 20:04:27terry.reedylinkissue32782 messages
2019-04-14 20:04:27terry.reedycreate