<div dir="ltr">I can humbly suggest why Python would deprecate the sequence protocol: there "should be one obvious way" to answer iter(), and in my opinion that's the  __iter__()  method.  I considered infinite iterators, and if you happen to have  __getitem__ written, you can trivially write an __iter__ function as follows:<div>

<br></div><div>def __iter__(self):</div><div>     return (self.__getitem__(x) for x in itertools.count())</div><div><br></div><div>Now your class will be Iterable in the abc sense, and no longer relies on the sequence protocol</div>

<div><br></div><div>Best,</div><div>Neil</div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Fri, Sep 20, 2013 at 10:41 PM, Stephen J. Turnbull <span dir="ltr"><<a href="mailto:stephen@xemacs.org" target="_blank">stephen@xemacs.org</a>></span> wrote:<br>

<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="im">Tim Delaney writes:<br>
<br>
 > Also, pathological is probably not the best term to use. Instead,<br>
 > substitute "deliberately breaks a well-established protocol".<br>
<br>
</div>Note that in Neil's use case (the OP) it's not deliberate.  His<br>
function receives an iterable, it naively iterates it and (if an<br>
iterator) consumes it, and then some other function loses.  Silently.<br>
<br>
Also, as long as __getitem__(0) succeeds, this *is* the "sequence<br>
protocol".  (A Sequence also has a __len__() method, but iterability<br>
doesn't depend on that.)<br>
<br>
I don't see why Python would deprecate this.  For example, consider<br>
the sequence of factors of integers: [(1,2), (1,3), (1,2,2,4), (1,5),<br>
(1,2,3,6), ...].  Factorization being in general a fairly expensive<br>
operation, you might want to define this in terms of __getitem__() but<br>
__len__() is infinite.  I admit this is a somewhat artificial example<br>
(I don't know of non-academic applications for this sequence, although<br>
factorization itself is very useful in applications like crypto).<br>
<div class="HOEnZb"><div class="h5">_______________________________________________<br>
Python-ideas mailing list<br>
<a href="mailto:Python-ideas@python.org">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
<br>
--<br>
<br>
---<br>
You received this message because you are subscribed to a topic in the Google Groups "python-ideas" group.<br>
To unsubscribe from this topic, visit <a href="https://groups.google.com/d/topic/python-ideas/OumiLGDwRWA/unsubscribe" target="_blank">https://groups.google.com/d/topic/python-ideas/OumiLGDwRWA/unsubscribe</a>.<br>
To unsubscribe from this group and all its topics, send an email to <a href="mailto:python-ideas%2Bunsubscribe@googlegroups.com">python-ideas+unsubscribe@googlegroups.com</a>.<br>
For more options, visit <a href="https://groups.google.com/groups/opt_out" target="_blank">https://groups.google.com/groups/opt_out</a>.<br>
</div></div></blockquote></div><br></div>