Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder2.hal-mli.net!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!cs.uu.nl!news.stack.nl!newsfeed.xs4all.nl!newsfeed4.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.106 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.79; '*S*': 0.00; 'cursor': 0.09; 'underlying': 0.09; 'subject:optimization': 0.16; 'wrote:': 0.17; 'stefan': 0.17; 'thu,': 0.17; 'all,': 0.21; 'thanks.': 0.21; 'header:In-Reply-To:1': 0.25; 'message-id:@mail.gmail.com': 0.27; 'subject:list': 0.28; 'efficiently': 0.29; 'large.': 0.29; 'skip:_ 10': 0.29; 'that.': 0.30; 'query': 0.30; 'implement': 0.32; 'could': 0.32; 'to:addr:python-list': 0.33; 'that,': 0.34; "can't": 0.34; 'received:google.com': 0.34; 'returning': 0.35; 'doing': 0.35; 'pm,': 0.35; 'really': 0.36; "didn't": 0.36; 'anything': 0.36; 'does': 0.37; 'rather': 0.37; 'subject:: ': 0.38; 'object': 0.38; 'to:addr:python.org': 0.39; 'subject:-': 0.40; 'back': 0.62; 'skip:n 10': 0.63; 'limit': 0.65; 'manner': 0.74; '2013': 0.84; 'presumably': 0.84; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=x-received:mime-version:in-reply-to:references:from:date:message-id :subject:to:content-type; bh=0Jcosl/VYGTzahmbqvNNzmKAU2Spl4hau4crW6pLkjo=; b=bxpfQaYIWSx7G56DzyvFDFlQDO/8Ajt8hqRgmkXhG6XA7jZfdxMFGMgLDPOlmzO2Iw A+E9Uffh6ugR38onUWuj8ewWmeuUDNbwnf2kTf5l7gvzKVHExuo7Gj+LQondaVPU0Ow8 Xb9Cn304TYg8PVsxNtdzR2LaQqk9TOJtOIFDF34bNXHx/Fmih/kjPyzEJYnTuaJtTDtP Cq7DOYxU80cMEHNYAFiOhUZUs8XG2FKbrHMDvrhfOGrKaHJXPj5jI8yxUl/gxcF6Tju9 hHZYZCL8pUvbqijWHbNYzj3Z/1t9us9KK1QnzZW/CEXNnjbjCgGQVbbICF4enmm0c1yY egIg== X-Received: by 10.220.205.195 with SMTP id fr3mr13380807vcb.6.1362688060173; Thu, 07 Mar 2013 12:27:40 -0800 (PST) MIME-Version: 1.0 In-Reply-To: References: <20130306215735.649932ee@bigbox.christie.dr> From: Ian Kelly Date: Thu, 7 Mar 2013 13:26:59 -0700 Subject: Re: Interesting list() un-optimization To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 13 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1362688062 news.xs4all.nl 6921 [2001:888:2000:d::a6]:44509 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:40819 On Thu, Mar 7, 2013 at 12:19 PM, Stefan Behnel 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.