Path: csiph.com!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsgate.cistron.nl!newsgate.news.xs4all.nl!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.013 X-Spam-Evidence: '*H*': 0.97; '*S*': 0.00; 'true,': 0.05; 'string': 0.09; 'caller': 0.09; 'function:': 0.09; 'optimizing': 0.09; 'def': 0.12; 'argument,': 0.16; 'factory': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'notation': 0.16; 'public,': 0.16; 'wrote:': 0.18; 'thu,': 0.19; '>>>': 0.22; 'fairly': 0.24; 'this:': 0.26; 'second': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'chris': 0.29; "doesn't": 0.30; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; "d'aprano": 0.31; 'purely': 0.31; 'steven': 0.31; 'skip:d 20': 0.34; 'something': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'surely': 0.36; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'enough': 0.39; 'happen': 0.63; 'here': 0.66; 'default': 0.69; 'jul': 0.74; '5:15': 0.84; 'snapshot': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=5DMMA9a29IXaHggq/7/yMZ/CYN1p6ELOOz1Mvam2nts=; b=YNixlz9vdlQtPrpKsotZ7vECDBU+g7EaVY6VlRcirgZZ39+SfSeUAaPsOWXhzb6reu E0RacO46e+/4er6p5w6pDC9/HUuwqoDmZ8Yk47Tlu5m55WpJuJBX2Ioul+sPrZc0bFoT Gs1nSpGRS0Hk5uf13F6yZHu7o7VN28QShBL7NVeRjmtt5Eji8CD+BO4amgtuxT++4KiC 8bX8W/x+93SVYcvxNgTsQdVMNQbMhkSIiZSkZkouQGSxYvRqIfM4xW3qm1TNX30MNT2T xaQx5LC20F5ptq1hynK83GOZO62ztskew3r+qbNXyD+R3x/n/S7dGjBEr1seCCrTwoN4 J/qQ== MIME-Version: 1.0 X-Received: by 10.52.16.105 with SMTP id f9mr17449004vdd.28.1373527386649; Thu, 11 Jul 2013 00:23:06 -0700 (PDT) In-Reply-To: <51de5b7b$0$29862$c3e8da3$5496439d@news.astraweb.com> References: <51de4b6c$0$11094$c3e8da3@news.astraweb.com> <51de5b7b$0$29862$c3e8da3$5496439d@news.astraweb.com> Date: Thu, 11 Jul 2013 17:23:06 +1000 Subject: Re: Documenting builtin methods From: Chris Angelico To: python-list@python.org 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: 43 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373527389 news.xs4all.nl 15888 [2001:888:2000:d::a6]:59793 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50423 On Thu, Jul 11, 2013 at 5:15 PM, Steven D'Aprano wrote: > On Thu, 11 Jul 2013 17:06:39 +1000, Chris Angelico wrote: > >> On Thu, Jul 11, 2013 at 4:06 PM, Steven D'Aprano >> wrote: >>> I think the right solution here is the trivial: >>> >>> def exhaust(it): >>> """Doc string here.""" >>> deque(maxlen=0).extend(it) >>> >>> >>> which will be fast enough for all but the tightest inner loops. But if >>> you really care about optimizing this: >>> >>> >>> def factory(): >>> eatit = deque(maxlen=0).extend >>> def exhaust_iter(it): >>> """Doc string goes here""" >>> eatit(it) >>> return exhaust_iter >>> >>> exhaust_it = factory() >>> del factory >>> >>> >>> which will be about as efficient as you can get while still having a >>> custom docstring. >> >> Surely no reason to go for the factory function: >> >> def exhaust(it,eatit=deque(maxlen=0).extend): >> eatit(it) > > Now you have the function accept a second argument, which is public, just > to hold a purely internal reference to something that you don't want the > caller to replace. True, but doesn't that happen fairly often with default args? Usually it's in the "int=int" notation to snapshot for performance. ChrisA