Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Ian Kelly Newsgroups: comp.lang.python Subject: Re: Meta decorator with parameters, defined in explicit functions Date: Fri, 1 Jul 2016 23:53:15 -0600 Lines: 25 Message-ID: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <85oa6gtxk3.fsf@benfinney.id.au> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 X-Trace: news.uni-berlin.de o950/7PWWQidSKFczwb/9wqCdosq/VuVtwxdnjrwE0Sg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.001 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'args': 0.04; '"""': 0.05; '*args,': 0.07; 'wrapper': 0.07; 'kwargs': 0.09; 'separately': 0.09; 'def': 0.13; '"""given': 0.16; '11:32': 0.16; '2016': 0.16; 'docstring': 0.16; 'received:io': 0.16; 'received:mail- oi0-x230.google.com': 0.16; 'received:psf.io': 0.16; 'subject:parameters': 0.16; 'wrote:': 0.16; 'thanks.': 0.18; 'header:In-Reply-To:1': 0.24; 'fri,': 0.27; 'message- id:@mail.gmail.com': 0.27; 'function': 0.28; '**kwargs)': 0.29; '**kwargs):': 0.29; 'accepts': 0.29; 'that,': 0.34; 'received:google.com': 0.35; 'skip:i 20': 0.36; 'should': 0.36; 'instead': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'expect': 0.37; 'sure': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'subject:with': 0.40; 'jul': 0.72; 'to:name:python': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to; bh=218dqfJTYYyj5RpWniYtcvQnxP/s2AaqufiXpmE9FIw=; b=ZuYCuiLirjdmiH5YCb6WoSt1Y4bIHeAVN4ntMgoHd/AQQuIsHDrINhhHLcFXKcVNFi tz0nGVDdkZcC1TAvMXxYVNj9U+evSNMG9W3iNMqxyi747O+ZiGFgBQPJcrqE7iV6tfvu 1tltjSK8wdkBdAVxINX7/fAJOFslx5Imm3+T9BiWBXCesnqDgOmHf1kZvCAI3PVUSIM/ wUeuQbiHp983kY7JTisIrFL/AHWCoiyguIZV3GEN7GtgxolBCZfmo89hZiy37K+6nX0S AWjWNUPePdB+5DjSs64TQRiS9wghpzb4ZQj4/KCr9HDvLZksN2kOA4p9vFyj6WiOkXIB tbdQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to; bh=218dqfJTYYyj5RpWniYtcvQnxP/s2AaqufiXpmE9FIw=; b=bmdFCaca8xdBKO7Snn5VEOKzclzYsfh0Crt1d2gLNTL0ZUzPsevABLYGOznqsN3e8i 77NbJeVqwNWNfdTAWlSxhvsk13OVULfWVdV2uNxttUEESAR8fre3fDhaVdZz2YWVOk6S w2tmW/rtXvu3tZmAtOhFq81IsnXlOTRlmyp15YsfjI6aJJ1h1ZUTuaqU0DN9oYQyDHnI w9ccEWD5vVtToRWLha8vr6gQAGJbOcEPnbSg20vC2+eil5IMakodcw9WCfDQrteH7Pe0 zqzfjQIolFxCj1y3eNagDzvD8/M6tYnXivUI+K3BdyaCFBtUpxOLDIuTU6LpnL3pi6NH CzfA== X-Gm-Message-State: ALyK8tJszEhyX0xE6dL0wsA8BElT+goIECZCmR1kwL1Q6iB1tJ2Mcyhb5IS1VU7WD/C++wkljJ6L9a4jPuX8xA== X-Received: by 10.202.231.83 with SMTP id e80mr1076958oih.159.1467438834909; Fri, 01 Jul 2016 22:53:54 -0700 (PDT) In-Reply-To: <85oa6gtxk3.fsf@benfinney.id.au> X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.22 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Mailman-Original-Message-ID: X-Mailman-Original-References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <85oa6gtxk3.fsf@benfinney.id.au> Xref: csiph.com comp.lang.python:110944 On Fri, Jul 1, 2016 at 11:32 PM, Ben Finney wrote: > Ian Kelly writes: > >> You should use functools.wraps instead of clobbering the decorated >> function's name and docstring: >> >> @functools.wraps(decorator) >> def decorate(*args, **kwargs): >> ... > > Thanks. Can you write the full implementation with that, so I can be > sure of where you expect that to go? def decorator_with_args(decorator): """Given function decorator(func, *args, **kwargs), returns a wrapper that accepts args and kwargs separately from func. """ @functools.wraps(decorator) def apply(*args, **kwargs): # inner_decorator is transient, so its name and docstring # are unimportant. def inner_decorator(func): return decorator(func, *args, **kwargs) return inner_decorator return apply