Message89637
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. |
|
Date |
User |
Action |
Args |
2009-06-23 18:40:02 | rhettinger | set | recipients:
+ rhettinger, r.david.murray |
2009-06-23 18:40:02 | rhettinger | set | messageid: <1245782402.41.0.142582030858.issue6329@psf.upfronthosting.co.za> |
2009-06-23 18:40:00 | rhettinger | link | issue6329 messages |
2009-06-23 18:40:00 | rhettinger | create | |
|