Path: csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed1.news.xs4all.nl!xs4all!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.012 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; 'skip:[ 20': 0.04; 'test,': 0.07; '3.0,': 0.09; 'function:': 0.09; 'interim': 0.09; 'wrapper': 0.09; 'cc:addr:python-list': 0.11; 'def': 0.12; 'attribute,': 0.16; 'collections': 0.16; 'deque': 0.16; 'docstring': 0.16; 'factory': 0.16; 'namespace,': 0.16; 'trivially': 0.16; 'sender:addr:gmail.com': 0.17; 'wrote:': 0.18; 'slightly': 0.19; 'seems': 0.21; '>>>': 0.22; 'import': 0.22; 'cc:addr:python.org': 0.22; 'skip:e 30': 0.24; 'cc:2**0': 0.24; 'pass': 0.26; 'post': 0.26; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'message- id:@mail.gmail.com': 0.30; 'too.': 0.31; 'constant': 0.31; 'doc': 0.31; 'overhead': 0.31; 'purely': 0.31; 'class': 0.32; 'could': 0.34; 'but': 0.35; 'received:google.com': 0.35; 'version': 0.36; 'too': 0.37; 'either': 0.39; 'ensure': 0.60; 'even': 0.60; 'simple': 0.61; 'times': 0.62; 'name': 0.63; 'july': 0.63; 'great': 0.65; 'needing': 0.65; 'to:addr:gmail.com': 0.65; 'friend': 0.79; ':).': 0.84; 'optimisation': 0.84; 'partial': 0.84; 'premature': 0.84; '2013': 0.98 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:sender:in-reply-to:references:from:date :x-google-sender-auth:message-id:subject:to:cc:content-type; bh=2+EYU0JO9CS9nZR7siNWh+4TAX2ThJv81yPngIj422s=; b=s6L3/Sq5gb5FRRgrMqvc0aYQLSM2o+dtInmp1S+HO3wl3pTtWMgEw+pMfVdmC0fLLs d9zuhDfnTZx0WM6xhpnaU9028F7ZbhnURkIypW5jQ/CUx7dix1jdNUk1znftLlpjUWNq CCkIc66xZs8MgIqhjDXSUU/kc+uTJudxjt6VOotGja837EDd3yqgFm1IoajCLcrbAMlW kqe/d3vc9iGygV9JoYnbVZeL//xeLBPIaqoZgbdKbDPBoK90Zw0vrTXT4kPOqwOfa/pY UAzZfj06a+Ae8n8hrX93bFJnJadw5jpgVuvr7e2lzKQ10BXCNMttCrAb2EzjcZFWuOo0 20Vw== X-Received: by 10.112.88.169 with SMTP id bh9mr18657191lbb.12.1373613037938; Fri, 12 Jul 2013 00:10:37 -0700 (PDT) MIME-Version: 1.0 Sender: joshua.landau.ws@gmail.com In-Reply-To: References: <51de4b6c$0$11094$c3e8da3@news.astraweb.com> From: Joshua Landau Date: Fri, 12 Jul 2013 08:09:57 +0100 X-Google-Sender-Auth: S1y_TPUEGc3Jneg0m9FGA6v7GVk Subject: Re: Documenting builtin methods To: alex23 Content-Type: text/plain; charset=UTF-8 Cc: python-list 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: 39 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1373613045 news.xs4all.nl 15898 [2001:888:2000:d::a6]:42740 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:50499 On 12 July 2013 04:43, alex23 wrote: > > My last post seems to have been eaten by either Thunderbird or the > EternalSeptember servers, but it contained an erroneous claim that the > straight function version performed as well as the factory one. However, in > the interim a co-worker has come up with a slightly faster variant: > > from functools import partial > from collections import deque > > class exhaust_it(partial): > """custom doc string""" > > exhaust_it = exhaust_it(deque(maxlen=0).extend) > > Shadowing the class name with the partial instance will ensure it has the > same name when accessed via help(), and it's a simple way to avoid needing > to clean up the namespace, as well. That's beautiful. You could even trivially make a wrapper function: def wrap_docstring(function, docstring, *, name=None): class Wrapper(partial): pass Wrapper.__name__ = function.__name__ if name is None else name Wrapper.__doc__ = docstring return Wrapper(function) which is no slower. You get great introspection through the "func" attribute, too :). Also: >>> times = time_raw(), time_function(), time_factory(), time_argument_hack(), time_partial() >>> [round(time/times[0], 1) for time in times] [1.0, 16.8, 3.1, 3.0, 1.8] This times almost purely the constant overhead by calling exhaust_iterabe on an empty iterable. So your friend wins the premature optimisation test, too.