The notion of what a sequence is seems to be somewhat ill-defined. If I execute for k in None: pass a TypeError is raised with "iteration over non-sequence" as the message. I searched the source for that message and found three occurrences, one each in Objects/{abstract,classobject,typeobject}.c. In abstract.c a non-sequence is an object which fails the PySequence_Check(s) test. In typeobject.c:slot_tp_iter, a sequence is defined to have a __getitem__ method. In classobject.c a sequence must have either __iter__ or __getitem__ and if __iter__ is defined, it must return something which passes PyIter_Check(). So, if I want to do a sniff test for a sequence is it "close enough" to execute (hasattr(s, "__getitem__") or hasattr(s, "__iter__")) or should I execute iter(s) ? Since this seems to be a fairly nebulous concept it makes sense to me that it should be defined somewhere. I checked the ref manual (types.html) in the Sequences section but saw nothing mentioned. If this is already defined somewhere I'd be happy to be pointed in the right direction. I would just update types.html if I knew what the answer was...
Skip, don't you think it's better to raise this kind of generic question in the python-dev list? This should probably lay down here for ever before a discussion raises to decide this.
What is the bug actually? "for k in s" is defined to work on any iterable, not only on sequences. And "iterable" is clearly defined, it's sufficient to check whether s.__iter__ exists or whether iter(s) succeeds...
(Sorry for the delay responding. Gmail thought Facundo's response was spam. :-/) In defense of my bug report, note that I submitted it in January 2003! It's quite possible that the docs have improved in this regard since then. If you think the docs are up-to-date in this regard now (I have no time to do a careful investigation) please close the ticket. Skip