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.

classification
Title: Fix object.__reversed__ doc
Type: Stage:
Components: Documentation Versions: Python 3.0, Python 3.1, Python 3.2, Python 2.7, Python 2.6
process
Status: closed Resolution: fixed
Dependencies: Superseder:
Assigned To: georg.brandl Nosy List: georg.brandl, terry.reedy
Priority: normal Keywords:

Created on 2009-05-16 03:18 by terry.reedy, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (2)
msg87852 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2009-05-16 03:18
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."
msg87878 - (view) Author: Georg Brandl (georg.brandl) * (Python committer) Date: 2009-05-16 11:13
Thanks, fixed in r72675.
History
Date User Action Args
2022-04-11 14:56:48adminsetgithub: 50284
2009-05-16 11:13:35georg.brandlsetstatus: open -> closed
resolution: fixed
messages: + msg87878
2009-05-16 03:18:06terry.reedycreate