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: Sun, 3 Jul 2016 18:01:21 -0600 Lines: 33 Message-ID: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de SlGvDWq82SJYhr8RJYseTg0u2oM80vumda1NEL+SD3Fg== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.003 X-Spam-Evidence: '*H*': 0.99; '*S*': 0.00; '*args,': 0.07; '*not*': 0.07; 'caller': 0.07; '*args': 0.09; 'caller.': 0.09; 'func': 0.09; 'def': 0.13; 'applies': 0.15; '"""returns': 0.16; '2016': 0.16; 'called,': 0.16; 'docstring': 0.16; 'earlier:': 0.16; 'namespace.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:@ 20': 0.16; 'subject:parameters': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'posted': 0.21; 'decorator': 0.22; 'lawrence': 0.22; 'sorry,': 0.22; 'code.': 0.23; 'replacing': 0.23; 'header:In- Reply-To:1': 0.24; "doesn't": 0.26; 'example': 0.26; 'not.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'see,': 0.27; 'function': 0.28; '**kwargs)': 0.29; '**kwargs):': 0.29; "i'm": 0.30; 'returned': 0.32; 'received:google.com': 0.35; 'but': 0.36; 'assigned': 0.36; 'monday,': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'being': 0.37; 'agree': 0.37; 'seem': 0.37; 'whatever': 0.39; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'your': 0.60; 'claim': 0.61; 'skip:u 10': 0.61; 'here:': 0.63; 'here': 0.66; 'talking': 0.67; 'skip:\xe2 10': 0.70; 'jul': 0.72; 'decorator,': 0.84; '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 :content-transfer-encoding; bh=gdoBoWHIO9uR48qUJEm/c9HbI8T8z+2nNl+SwSJUpas=; b=uThiK1pGIMcakHGx265U4aCm6K4V8OF1fq1n4LeO3pPCO12uuSdm2iIX/HXk0vJAgk dkqyVkF9Akh3byNH3sLpAfbn1rtiwgg5AJ1KFyksZf94nDuuHIC4+nCoj+BJlY0AOCNr IUFlxhuFdG1tUXSQh3LxPrXL57en3miywLyQ5s8sHMG0nTApp6tS+diZQ0e6jpgb14Un 8qjZAs/AZFUFQ2Mdi3bLv3LCYXQdrt8vGfVS5QHCj/00Y7LXK2k+H9cIBjqo2Jgugj9o QCsIm1e9fvHx5TjMJmpWG2TP0RewcI1I/M58mZqJqblp0AYTpvDZkfKGEOOLocLUntoE 6YNA== 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:content-transfer-encoding; bh=gdoBoWHIO9uR48qUJEm/c9HbI8T8z+2nNl+SwSJUpas=; b=bQhWZkxcipIKNMbtQfQulnwNpSDnq91koO31Y//glfPMDYaFhtHs/SAl0LvjAZysvr 9KNMNvMz5vJYrxtm4QuumG2p3xvD6c81teru+9jMcvsL9B/TAFHCqDJppdYVNeIqZxw+ lzAVwO89Dx3xSFlK/5e3VITGdhezlm5Wbn3tRoa0A6SS900rIy+gRIULUMqYD1s1UXkS 3+f6kFtp+/02j6Dwrmtzs8Z8C3prXmtReXB4Osttlbf6WjBI08dAr5lQFtAoj/Mxj5K+ KXu6gk5IpiZ52l56wA/L+s3AshZ6mCbZM9M7Sp4PPPGzjs+cK1PN2r3sdArrZxznmUAi EoYg== X-Gm-Message-State: ALyK8tImpM6SnUCrlxtOzy4vmRncUUNDXqdQ7JvGc6XjABYHch49NH2Uj83Wl7T53h+0lROQSq5OYsnYiHM8KQ== X-Received: by 10.202.181.137 with SMTP id e131mr5545011oif.144.1467590520822; Sun, 03 Jul 2016 17:02:00 -0700 (PDT) In-Reply-To: <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> 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> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <62b43f29-e6ea-4d19-9e9f-1becb3988bd3@googlegroups.com> Xref: csiph.com comp.lang.python:111025 On Sun, Jul 3, 2016 at 5:25 PM, Lawrence D=E2=80=99Oliveiro wrote: > On Monday, July 4, 2016 at 10:39:30 AM UTC+12, Ian wrote: >> Sorry, but you're the one who doesn't seem to get it. Because it's a >> decorator, "your" function is replacing the caller's function in the >> caller's namespace. > > No it is not. The replacement happens here: > > def generated_decorator(func) : > return \ > decorator(func, *args, **kwargs) > #end generated_decorator > > As you can see, the function being called, =E2=80=9Cdecorator=E2=80=9D, i= s supplied by the caller. The function being decorated, =E2=80=9Cfunc=E2=80= =9D, is supplied by the caller (along with the additional *args and **kwarg= s). And the returned function is returned *as-is*, so whatever docstring wa= s assigned by the caller is *NOT* =E2=80=9Cclobbered=E2=80=9D. I'm talking about the docstring of the *decorator*, not func. I agree that whatever docstring func has is entirely up to func and the decorator, not your code. Here again is the example I posted earlier: >>> @decorator_with_args ... def my_decorator(func, *args, **kwargs): ... """Returns func unmodified.""" ... return func ... >>> my_decorator.__doc__ 'generates a decorator which applies my_decorator to the given arguments' I never made any claim about the docstring of the decorated func.