On Wed, Dec 12, 2018 at 12:50:41PM +1300, Greg Ewing wrote:
> Steven D'Aprano wrote:
> >The iterator protocol is that iterators must:
> >
> >- have a __next__ method;
> >- have an __iter__ method which returns self;
> >
> >and the test for an iterator is:
> >
> >obj is iter(obj)
>
> By that te
>>> and the test for an iterator is:
>>>
>>> obj is iter(obj)
Is that a hard and fast rule? I know it’s the vast majority of cases,
but I imagine you could make an object that behaved exactly like an
iterator, but returned some proxy object rather that itself.
Not sure why one would do that, bu
On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
Python-ideas wrote:
>
> >>> and the test for an iterator is:
> >>>
> >>> obj is iter(obj)
>
> Is that a hard and fast rule? I know it’s the vast majority of cases,
> but I imagine you could make an object that behaved exactly like a
On Wed, Dec 12, 2018 at 08:06:17PM -0800, Chris Barker - NOAA Federal wrote:
> >>> and the test for an iterator is:
> >>>
> >>> obj is iter(obj)
>
> Is that a hard and fast rule?
Yes, that's the rule for the iterator protocol.
Any object can have an __iter__ method which returns anything you
Chris Angelico wrote:
On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
Python-ideas wrote:
obj is iter(obj)
Is that a hard and fast rule?
Yes, it is.
https://docs.python.org/3/library/stdtypes.html#iterator-types
The docs aren't very clear on this point. They claim this i
On Thu, Dec 13, 2018 at 4:54 PM Greg Ewing wrote:
>
> Chris Angelico wrote:
> > On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
> > Python-ideas wrote:
> >
> > obj is iter(obj)
> >>
> >>Is that a hard and fast rule?
> > Yes, it is.
> >
> > https://docs.python.org/3/library/st