<div dir="ltr">Can you help understand how this is a Liskov substitution violation? A Sequence is an Iterator. Getting the sequence back should never hurt. The current interface doesn't promise that the returned object won't have additional methods or implement additional interfaces, does it?<br><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 30, 2015 at 12:43 PM Brett Cannon <<a href="mailto:brett@python.org">brett@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, 30 Sep 2015 at 09:38 Neil Girdhar <<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">In fairness, one is a superset of the other. You always get an Iterable. You sometimes get a Sequence. It's a bit like multiplication? with integers you get integers, with floats, you get floats.</div></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>No, it's not like multiplication. =) I hate saying this since I think it's tossed around too much, but int/float substitution doesn't lead to a Liskov substitution violation like substituting out a sequence for an iterator (which is what will happen if the type of the argument to `enumerate` changes). And since you can just call `list` or `tuple` on enumerate and get exactly what you're after without potential bugs cropping up if you don't realize from afar you're affecting an assumption someone made, I'm -1000 on this idea.</div></div></div><div dir="ltr"><div class="gmail_quote"><div><br></div><div>-Brett</div></div></div><div dir="ltr"><div class="gmail_quote"><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><br><div class="gmail_quote"><div dir="ltr">On Wed, Sep 30, 2015 at 12:35 PM Brett Cannon <<a href="mailto:brett@python.org" target="_blank">brett@python.org</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_quote"><div dir="ltr">On Wed, 30 Sep 2015 at 08:28 Neil Girdhar <<a href="mailto:mistersheik@gmail.com" target="_blank">mistersheik@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">What are the pros and cons of making enumerate a sequence if its argument is a sequence?<div><font><font><br></font></font></div><div><font><font>I found myself writing:</font></font></div><div><font><font><font><font><br></font></font></font></font></div><div><font><font><font><font><div> for vertex, height in zip(</div><div> self.cache.height_to_vertex[height_slice],</div><div> range(height_slice.start, height_slice.stop)):</div><div><br></div><div>I would have preferred:</div><div><br></div><div><div> for height, vertex in enumerate(</div><div> self.cache.height_to_vertex)[height_slice]:<br></div></div></font></font></font></font></div></div></blockquote><div><br></div></div></div><div dir="ltr"><div class="gmail_quote"><div>Because you now suddenly have different types and semantics of what enumerate() returns based on its argument which is easy to mess up if self.cache.height_to_vertex became an iterator object itself instead of a sequence object. It's also not hard to simply do `tuple(enumerate(...))` to get the exact semantics you want: TOOWTDI.</div><div><br></div><div>IOW all I see are cons. =) </div></div></div>
</blockquote></div>
</blockquote></div></div></blockquote></div></div>