On Thu, Mar 7, 2013 at 12:19 PM, Stefan Behnel <stefan...@behnel.de> wrote: >> Didn't know about that, thanks. Presumably a proper iter(QuerySet()) >> object could implement __length_hint__ in an efficient manner rather >> than by just calling the __len__ of the underlying QuerySet, > > And how exactly would it do that, without either doing what __len__ does or > reading the whole result set into memory?
If the underlying cursor provides its own efficient length hint, it could return that. Or if the query is result-limited, use the limit as a length hint, provided it's not absurdly large. And if you really can't efficiently determine anything about the length of the result set at all, you can always fall back on returning NotImplemented. -- http://mail.python.org/mailman/listinfo/python-list