[Python-Dev] PEP 246: lossless and stateless

Phillip J. Eby pje at telecommunity.com
Sat Jan 15 23:23:56 CET 2005


At 10:48 PM 1/15/05 +0100, Simon Percivall wrote:
>On 2005-01-15, at 18.06, Phillip J. Eby wrote:
>>At 05:32 PM 1/15/05 +0100, Just van Rossum wrote:
>>>Phillip J. Eby wrote:
>>>
>>> > >It's not at all clear to me that "sticky" behavior is the best
>>> > >default behavior, even with implicit adoptation. Would anyone in
>>> > >their right mind expect the following to return [0, 1, 2, 3, 4, 5]
>>> > >instead of [0, 1, 2, 0, 1, 2]?
>>> > >
>>> > >   >>> from itertools import *
>>> > >   >>> seq = range(10)
>>> > >   >>> list(chain(islice(seq, 3), islice(seq, 3)))
>>> > >   [0, 1, 2, 0, 1, 2]
>>> > >   >>>
>>> >
>>> > I don't understand why you think it would.  What does islice have to
>>> > do with adaptation?
>>>
>>>islice() takes an iterator, yet I give it a sequence.
>>
>>No, it takes an *iterable*, both practically and according to its 
>>documentation:
>
>But it _does_ perform an implicit adaptation, via PyObject_GetIter.

First, that's not implicit.  Second, it's not adaptation, 
either.  PyObject_GetIter invokes the '__iter__' method of its target -- a 
method that is part of the *iterable* interface.  It has to have something 
that's *already* iterable; it can't "adapt" a non-iterable into an iterable.

Further, if calling a method of an interface that you already have in order 
to get another object that you don't is adaptation, then what *isn't* 
adaptation?  Is it adaptation when you call 'next()' on an iterator? Are 
you then "adapting" the iterator to its next yielded value?

No?  Why not?  It's a special method of the "iterator" interface, just like 
__iter__ is a special method of the "iterable" interface.

So, I can't see how you can call one adaptation, but not the other.  My 
conclusion: neither one is adaptation.


>  A list has no next()-method, but iter(list()) does.

But a list has an __iter__ method, so therefore it's an iterable.  That's 
what defines an iterable: it has an __iter__ method.  It would only be 
adaptation if lists *didn't* have an __iter__ method.



More information about the Python-Dev mailing list