[Chicago] duck typing to handle a string or iterable of strings

Carl Meyer carl at oddbird.net
Fri May 20 17:34:40 CEST 2011

Hey Alex,

On 05/19/2011 10:55 PM, Alex Gaynor wrote:
> It wasn't in any way an oversight, in fact the __iter__ on list and
> tuples are totally superflous.  Types which define __getitem__ are
> automatically iterable and a default iterator is used for them which
> calls __getitem__ with successive integers until an IndexError is raised.

Yes, I know about the __getitem__ iteration fallback :-) Obviously you
can iterate over a string in Python 2.

"Oversight" may have been a strong word, but it was decided to make an
intentional shift that all iterable objects should have an __iter__
method (its part of the Iterable ABC interface). It seems at least
halfway reasonable, in light of this decision for greater consistency,
to characterize the earlier omission, in retrospect, an "oversight." Or
perhaps not ;-)


More information about the Chicago mailing list