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 georg.brandl, terry.reedy
Date 2009-05-16.03:18:05
SpamBayes Score 7.164919e-11
Marked as misclassified No
Message-id <1242443888.15.0.235862846371.issue6034@psf.upfronthosting.co.za>
In-reply-to
Content
3.3.5. Emulating container types
object.__reversed__(self)
says in 3.0 and 3.1 and I assume in 2.x:
"Objects should normally only provide __reversed__() if they do not
support the sequence protocol and an efficient implementation of reverse
iteration is possible."

The builtin sequences violate this because because they do support the
sequence and have __ reversed__ methods anyway.  And iterables that do
not support that protocol obviously *must* provide a method to be
reverse iterable.

I believe the point is that it is hard for Python code to beat the
C-coded version of the obvious

def __reversed__(self):
   for i in reversed(range(self.__len__)):
      yield self.__getitem__(i)

So I think the entry should say: "Objects that support the sequence
protocol should only provide __reversed__ if they can provide an
implementation that is more efficient than the one provided by
reversed()." possibly followed by "Objects that do not supposrt the
sequence protocol must provide __reversed__ to be reverse iterable."
History
Date User Action Args
2009-05-16 03:18:08terry.reedysetrecipients: + terry.reedy, georg.brandl
2009-05-16 03:18:08terry.reedysetmessageid: <1242443888.15.0.235862846371.issue6034@psf.upfronthosting.co.za>
2009-05-16 03:18:06terry.reedylinkissue6034 messages
2009-05-16 03:18:05terry.reedycreate