New submission from Raymond Hettinger <rhettin...@users.sourceforge.net>:
Despite being a sequence (with both __getitem__ and __len__ defined), memoryview objects were not recognized as being iterable. The docs say that all such sequences are iterable, so this is a bug. >>> b = b'abcde' >>> m = memoryview(b) >>> list(m) Traceback (most recent call last): File "<pyshell#2>", line 1, in <module> list(m) TypeError: 'memoryview' object is not iterable The underlying problem is that the __getitem__ method is listed in the as_mapping section instead of as_sequence. This was necessary so that the ellipsis could be supported (the mapping version accepts arbitrary objects while the sequence version only accepts integer indices). Unfortunately, the logic for Objects/abstract.c::PySeq_Iter() expects to find the getitem defined in s->ob_type->tp_as_sequence->sq_item slot. This patch attaches the appropriate code in that slot. The code is a simple cut and paste from the more general memory_subscript() function listed just above. ---------- assignee: r.david.murray components: Interpreter Core files: mview.diff keywords: patch messages: 89637 nosy: r.david.murray, rhettinger priority: high severity: normal stage: patch review status: open title: Fix iteration for memoryviews type: behavior versions: Python 3.1 Added file: http://bugs.python.org/file14344/mview.diff _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue6329> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com