2009/4/2 Daniel Stutzbach <daniel at stutzbachenterprises.com>: > Iterators can implement a method called __length_hint__ that provides a hint > to certain internal routines (such as list.extend) so they can operate more > efficiently. As far as I can tell, __length_hint__ is currently > undocumented. Should it be? This has been discussed, and no, it is a implementation detail mostly for the optimization of builtin iterators. > > If so, are there any constraints on what an iterator should return? I can > think of 3 possible rules, each with advantages and disadvantages: > 1. return your best guess > 2. return your best guess that you are certain is not higher than the true > value > 3. return your best guess that you are certain is not lower than the true > value > > Also, I've noticed that if a VERY large hint is returned by the iterator, > list.extend will sometimes disregard the hint and try to allocate memory > incrementally (correct for rule #1 or #2). However, in another code path it > will throw a MemoryError immediately based on the hint (correct for rule > #3). Perhaps Raymond can shed some light on these. -- Regards, Benjamin
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4