Hello,

Well, I guess this isn't a bug (its only a hint) - but IronPython doesn't use length hint. :-)

CPython
>>> class X(object):
...  def __iter__(self):
...   return iter([1,2,3])
...  def __length_hint__(self):
...   print 'length hint'
...   return 3
...
>>> x = X()
>>> list(x)
length hint
[1, 2, 3]

IronPython
>>> class X(object):
...  def __iter__(self):
...   return iter([1,2,3])
...  def __length_hint__(self):
...   print 'length hint'
...   return 3
...
>>> x = X()
>>> list(x)
[1, 2, 3]
>>>

CPython uses it as an optimisation to preallocate space for the list.

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.

Michael

--
http://www.ironpythoninaction.com/
http://www.voidspace.org.uk/blog


_______________________________________________
Users mailing list
[email protected]
http://lists.ironpython.com/listinfo.cgi/users-ironpython.com

Reply via email to