Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed2.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.032 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'string': 0.09; 'function:': 0.09; 'optimizing': 0.09; 'def': 0.12; 'factory': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'wrote:': 0.18; 'thu,': 0.19; 'this:': 0.26; 'header:In-Reply- To:1': 0.27; 'message-id:@mail.gmail.com': 0.30; "d'aprano": 0.31; 'steven': 0.31; 'skip:d 20': 0.34; '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; 'here': 0.66; 'jul': 0.74; '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=KAhu4WvrySeDbZm7vDXI1yDp8v4tgmdvVF8lzhs0eK4=; b=H+2nVQOjs72JJKQMSrmV4TBzyyuDJOg+GMqiNJ6X6MQ4fXWTAMc5tlRV/lVYJEQXVR UH7SpokBRW+FOWlUjw6JgG7JzEZ6ADd8FL//RbEtzHcGVtdTlbBLh6wC+hLD8TNMxcvQ WzYn1rTTgL5pS8gv2oLi/0ywdqp3zUaZw/L4mmRyY6fNIFw2bVvms4zoNaUJ3qw92MeA kTsZKj3xV2+HLLHMpJOSlAyhIlr/BVi1ZP3cK8g7tc5g8bOcKUoMn+5mDUcK8rQIXoWG p1RiPIrq/ZzRDZXd6tFboIKR+S6D2qto4SpZ60DI/hgVKUayQ3yrUlC+gqbiaZmS8t+r 6Jvg== MIME-Version: 1.0 X-Received: by 10.52.163.165 with SMTP id yj5mr17686609vdb.104.1373526399907; Thu, 11 Jul 2013 00:06:39 -0700 (PDT) In-Reply-To: <51de4b6c$0$11094$c3e8da3@news.astraweb.com> References: <51de4b6c$0$11094$c3e8da3@news.astraweb.com> Date: Thu, 11 Jul 2013 17:06:39 +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: 32 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373526402 news.xs4all.nl 15985 [2001:888:2000:d::a6]:52764 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50421 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) ChrisA