[Python-Dev] Re: PEP 322: Reverse Iteration

Alex Martelli aleaxit at yahoo.com
Wed Nov 5 18:02:29 EST 2003

On Wednesday 05 November 2003 23:21, Guido van Rossum wrote:
> > > >The __reversed__ protocol muddles the issue by inviting to
> > > > try to make reversed() work for some iterators
> >
> > The invitation is to add efficient reverse iteration support to regular
> > objects and user defined classes, not for iterators.  Though I won't be
> > suprised if someone tries, the only iterator that has a chance with
> > this is enumerate, but that is not what the hook is for.
> Yeah, but there was widespread misunderstanding here (for a while even
> you and Alex were convinced that it was possible for enumerate).

It _is_ *possible*; it is not necessarily _opportune_ -- a different issue.
Similarly, you point out below possibilities that may not be opportune.

> So, unless you want to open this can of worms, I'd be for a version of
> reversed() that does *not* support __reversed__, making it perfectly
> clear it only applies to real sequences.

Unless some _opportune_ (i.e., truly good:-) use case of "naturally 
reversible nonsequence" (doubly linked list...?-) arises (and the
__reversed__ idea can inserted then -- just as it could be removed
if reversed started out with it -- as long as we do it before the beta)
reversed with or without __reversed__ seem anyway fine to me --
arguments being so finely balanced on both sides.


More information about the Python-Dev mailing list