<div>The CPython test suite says specifically<br></div><div><br></div><div><div># note: this is an internal undocumented API</div><div># don't rely on it in your own programs</div><div><br></div><div>so I don't feel too bad about it. :)</div>
<br><div class="gmail_quote">On Fri, Oct 31, 2008 at 3:12 PM, Michael Foord <span dir="ltr"><<a href="mailto:fuzzyman@voidspace.org.uk">fuzzyman@voidspace.org.uk</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex;">
Hello,<br>
<br>
Well, I guess this isn't a bug (its only a hint) - but IronPython doesn't use length hint. :-)<br>
<br>
CPython<br>
>>> class X(object):<br>
... def __iter__(self):<br>
... return iter([1,2,3])<br>
... def __length_hint__(self):<br>
... print 'length hint'<br>
... return 3<br>
...<br>
>>> x = X()<br>
>>> list(x)<br>
length hint<br>
[1, 2, 3]<br>
<br>
IronPython<br>
>>> class X(object):<br>
... def __iter__(self):<br>
... return iter([1,2,3])<br>
... def __length_hint__(self):<br>
... print 'length hint'<br>
... return 3<br>
...<br>
>>> x = X()<br>
>>> list(x)<br>
[1, 2, 3]<br>
>>><br>
<br>
CPython uses it as an optimisation to preallocate space for the list.<br>
<br>
You can bet somebody, somewhere is writing code that depends on length hint being called... Actually probably not, but it's one of those methods like '__reversed__' and '__missing__' that I've only recently discovered. I was impressed that IronPython supported '__missing__' by the way.<br>
<br>
Michael<br>
<br>
-- <br>
<a href="http://www.ironpythoninaction.com/" target="_blank">http://www.ironpythoninaction.com/</a><br>
<a href="http://www.voidspace.org.uk/blog" target="_blank">http://www.voidspace.org.uk/blog</a><br>
<br>
<br>
_______________________________________________<br>
Users mailing list<br>
<a href="mailto:Users@lists.ironpython.com" target="_blank">Users@lists.ironpython.com</a><br>
<a href="http://lists.ironpython.com/listinfo.cgi/users-ironpython.com" target="_blank">http://lists.ironpython.com/listinfo.cgi/users-ironpython.com</a><br>
</blockquote></div><br></div>