195Re: [python-iter] Questioning the problem... how about __queryinterface__ ?
- Mar 17, 2001Thank you for responding -- evidently I'm not
being clear (did you read the second post, and
not the brain-dead first version?).
On 17 Mar 2001 qrczak@... wrote:
> > This makes me wonder if our context is broad enough? It seems like
> > the primary role of __iter__ is to provide a particular interface
> > for an object.
> I see nothing special about __iter__. It's just a common functionality
> of some kinds of objects, like __getitem__, keys, __len__, __str__
> or readline.
__iter__ has two different roles depending upon class,
(a) to return a new iterator if the class is not an iterator, or
(b) to return self if the class is already an iterator.
None of the above have this type of special behavior... right?
> (The fact that it's tp_iter slot and __iter__ method instead of iter
> method is an artifact of Python's type/class dichotomy ...
Ok. Then why isn't next going to use a slot, just like __getitem__ ?
I see nothing special about next... other than it is more difficult
to implement __next__ as a slot.
> __iter__() call is not "coerce to iterator". An iterator is not the
> original object viewed differently, but a tool to examine contents
> of the object.
QueryInterface is very vague in this respect, it does
not imply "coerce to". It is a generic method for
getting a particular interface from an object.
And note, that it is very common to "return self"
in a QueryInterface.
It just seemed to me that with "next" instead of "__next__"
we are introducing the concept of an interface, no? And that
__iter__ is equivalent to something like __getinterface__("iterator")
> Each call to __iter__() produces a new independent iterator.
Since when does __iter__ on an iterator return
a new independent iterator?
a) It is clear to me that "iterator" is an interface
b) Guido said that adding slots and built-in methods is painful.
Therefore, I'm suggesting that a generic, "get me an object with
this particular interface" could be added instead of a "get me this
iterator" built-in. This does very little to change the current
solution, but makes it more generic so that other interfaces
can be added later... with out the need to add another __special__
method and slot.
I'm saying that many many things will have the same *pattern*
as iterators. Let's not just solve iterators, let's solve
- << Previous post in topic