[Python-Dev] PEP 246: lossless and stateless

Simon Percivall s.percivall at chello.se
Sun Jan 16 00:02:20 CET 2005


On 2005-01-15, at 23.50, Just van Rossum wrote:
> Phillip J. Eby wrote:
>
>>> 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?
>
> That's one (contrived) way of looking at it. Another is that
>
>   y = iter(x)
>
> adapts the iterable protocol to the iterator protocol.

Especially since an iterable can also be an object without an __iter__
method but with a __getitem__ method. Calling __iter__ might get an
iterator, but calling __getitem__ does not. That seems like adaptation.
No? It's still not clear to me, as this shows, exactly what counts as
what in this game.

//Simon



More information about the Python-Dev mailing list