cpython icon indicating copy to clipboard operation
cpython copied to clipboard

bpo-39610: Raise TypeError for len(memoryview_0d)

Open eric-wieser opened this issue 4 years ago • 2 comments

This makes memoryview.__len__ consistent with memoryview.__getitem__.

https://bugs.python.org/issue39610

(#83791)

eric-wieser avatar Feb 11 '20 15:02 eric-wieser

Codecov Report

Merging #18463 into master will increase coverage by 0.02%. The diff coverage is n/a.

Impacted file tree graph

@@            Coverage Diff             @@
##           master   #18463      +/-   ##
==========================================
+ Coverage   82.11%   82.13%   +0.02%     
==========================================
  Files        1955     1955              
  Lines      588958   584775    -4183     
  Branches    44428    44488      +60     
==========================================
- Hits       483632   480330    -3302     
+ Misses      95677    94794     -883     
- Partials     9649     9651       +2     
Impacted Files Coverage Δ
Lib/distutils/tests/test_bdist_rpm.py 30.00% <0.00%> (-65.00%) :arrow_down:
Lib/distutils/command/bdist_rpm.py 7.63% <0.00%> (-56.88%) :arrow_down:
Modules/_decimal/libmpdec/umodarith.h 80.76% <0.00%> (-19.24%) :arrow_down:
Lib/test/test_urllib2net.py 76.92% <0.00%> (-13.85%) :arrow_down:
Lib/test/test_smtpnet.py 78.57% <0.00%> (-7.15%) :arrow_down:
Lib/ftplib.py 63.85% <0.00%> (-6.06%) :arrow_down:
Lib/test/test_ftplib.py 87.11% <0.00%> (-4.72%) :arrow_down:
Tools/scripts/db2pickle.py 17.82% <0.00%> (-3.97%) :arrow_down:
Tools/scripts/pickle2db.py 16.98% <0.00%> (-3.78%) :arrow_down:
Lib/test/test_socket.py 71.94% <0.00%> (-3.77%) :arrow_down:
... and 399 more

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update f3e7ea5...c210029. Read the comment docs.

codecov[bot] avatar Mar 02 '20 11:03 codecov[bot]

All commit authors signed the Contributor License Agreement.
CLA signed

cpython-cla-bot[bot] avatar Jul 07 '22 20:07 cpython-cla-bot[bot]

@mdickinson: any chance you're willing to review one more buffer-related PR? This one isn't quite as old as the other two of mine you rescued, but it's getting close!

eric-wieser avatar Apr 12 '23 22:04 eric-wieser

I'm afraid I don't remember what I considered at the time (which is obviously a lesson in writing better commit messages). I'll see if I can come up with an argument either way.

eric-wieser avatar Apr 13 '23 07:04 eric-wieser

I suspect consistency with numpy was the main argument; along with consistency with to_list:

>>> import numpy as np
>>> arr_0d = np.array(42)
>>> mem_0d = memoryview(arr_0d)

>>> len(arr_0d)
TypeError: len() of unsized object
>>> len(mem_0d.tolist())
TypeError: object of type 'int' has no len()
>>> len(mem_0d)
TypeError: 0-dim memory has no length  # with this PR

eric-wieser avatar Apr 19 '23 23:04 eric-wieser