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 rhettinger
Recipients r.david.murray, rhettinger
Date 2009-06-23.18:39:59
SpamBayes Score 1.1234278e-09
Marked as misclassified No
Message-id <1245782402.41.0.142582030858.issue6329@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2009-06-23 18:40:02rhettingersetrecipients: + rhettinger, r.david.murray
2009-06-23 18:40:02rhettingersetmessageid: <1245782402.41.0.142582030858.issue6329@psf.upfronthosting.co.za>
2009-06-23 18:40:00rhettingerlinkissue6329 messages
2009-06-23 18:40:00rhettingercreate