<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Fri, Dec 12, 2014 at 12:14 PM, Alexander Belopolsky <span dir="ltr"><<a href="mailto:alexander.belopolsky@gmail.com" target="_blank">alexander.belopolsky@gmail.com</a>></span> wrote:<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div><div class="h5"><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div class="gmail_extra">This gets you a custom iterable.  The corresponding iterator will be the buitin iterator type:</div><div class="gmail_extra"><br></div><div class="gmail_extra"><div class="gmail_extra">>>> class X:</div><div class="gmail_extra">...   __getitem__ = None</div><div class="gmail_extra">...</div><div class="gmail_extra">>>> iter(X())</div><div class="gmail_extra"><iterator object at 0x10b2a70b8></div></div></blockquote></div><br></div></div>The same logic applies to generators and I think this misconception is at the root of the confusion in this thread.   When you are writing a generator function, you are not creating a custom TIIP.  You are writing a code object that Python knows how to convert into an instance of a built-in TIIP (the generator type).</div></div></blockquote><div><br></div><div>The point was supposed to be that you want a TIIP with particular behavior that is not built-in (hence custom). Yes, in terms of type, a generator function, when called, will return the a built-in type, but its behavior is customized.</div><div><br></div><div>Indeed the same as writing a class with __getitem__ and no __iter__ or __next__ will give you an instance a built-in iterator type with customized behavior.</div><div><br></div><div>I guess my take is that the user shouldn't have to know exactly what the type of TIIP is produced is -- only what its behavior will be.</div><div><br></div><div>But maybe that IS the source of much of this confusion -- the PEP authors make the point that generators are something special. I want tend to think of them as an implementation detail. This PEP makes them more special, and that's really the point of the contentious part of the PEP.</div><div><br></div><div>So maybe that's the the point we are trying to make -- while we can argue about whether generators ARE iterators, or whether they have been "conflated" -- generators are special, and might as well be more special ;-)</div><div><br></div><div>-Chris</div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div><br></div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">_______________________________________________<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>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br></blockquote></div><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><br>Christopher Barker, Ph.D.<br>Oceanographer<br><br>Emergency Response Division<br>NOAA/NOS/OR&R            (206) 526-6959   voice<br>7600 Sand Point Way NE   (206) 526-6329   fax<br>Seattle, WA  98115       (206) 526-6317   main reception<br><br><a href="mailto:Chris.Barker@noaa.gov" target="_blank">Chris.Barker@noaa.gov</a></div>
</div></div>