Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-12 Thread Steven D'Aprano
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

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-12 Thread Chris Barker - NOAA Federal via Python-ideas
>>> 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

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-12 Thread Chris Angelico
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

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-12 Thread Steven D'Aprano
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

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-12 Thread Greg Ewing
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

Re: [Python-ideas] Suggested MapView object (Re: __len__() for map())

2018-12-12 Thread Chris Angelico
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