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

Greg Ewing greg.ewing at canterbury.ac.nz
Thu Dec 13 00:53:54 EST 2018


Chris Angelico wrote:
> On Thu, Dec 13, 2018 at 3:07 PM Chris Barker - NOAA Federal via
> Python-ideas <python-ideas at python.org> 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 is necessary
so that the iterator can be used in a for-loop, but that's obviously
not strictly true, since a proxy object could also be used.

They also make no mention about whether one should be able to rely
on this as a definitive test of iterator-ness.

In any case, I don't claim that my MapView implements the full
iterator protocol, only enough of it to pass for an iterator in
most likely scenarios that assume one.

-- 
Greg


More information about the Python-ideas mailing list