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 05:52:47 -0600 Lines: 46 Message-ID: References: <85mvm5vrbw.fsf@benfinney.id.au> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable X-Trace: news.uni-berlin.de WJhOxqWGaNdcrQVyGr5cqAOvtsXUIvLMh3i0a3SVBroA== Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.002 X-Spam-Evidence: '*H*': 1.00; '*S*': 0.00; 'source.': 0.05; 'that?': 0.05; '*args,': 0.07; 'func': 0.09; 'interpreter,': 0.09; 'naturally': 0.09; 'useful,': 0.13; 'def': 0.13; 'applies': 0.15; 'interpreter': 0.15; '"""returns': 0.16; '2016': 0.16; 'docstring': 0.16; 'posted:': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'skip:@ 20': 0.16; 'subject:parameters': 0.16; 'wrote:': 0.16; '>>>': 0.20; 'decorator': 0.22; 'function,': 0.22; 'lawrence': 0.22; 'am,': 0.23; 'sat,': 0.23; 'this:': 0.23; 'header:In-Reply-To:1': 0.24; 'skip:" 20': 0.26; 'not.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; '**kwargs):': 0.29; 'does,': 0.29; 'objects': 0.29; 'somebody': 0.30; 'writes': 0.30; 'realize': 0.32; 'returned': 0.32; 'useful': 0.33; 'source': 0.33; 'though.': 0.33; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; "isn't": 0.35; 'but': 0.36; 'too': 0.36; 'should': 0.36; 'instead': 0.36; 'assigned': 0.36; 'skip:m 40': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'doing': 0.38; 'no,': 0.38; 'does': 0.39; 'to:addr:python.org': 0.40; 'where': 0.40; 'subject:with': 0.40; 'some': 0.40; 'skip:u 10': 0.61; 'saturday,': 0.63; '>>>>>': 0.66; '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=khkwpklGD+PrVZEHYMlM7uEYX4y+pMDSz5qdl2TfcH4=; b=huMq1F52vUShcMXfmb5PyBMR6OEnAlq6umN/TpxhNi7zZtcUhreYPkmgAlTDXgnn16 AjBJuz18ojtZTUF6j5yt0Zk57mNr/5K/0te+JhcjoamH1+rtsqRIZwiEPOcp2G1j6l8c r1QZksGMcqY9qT+bEG7hRM4iTZ7FOL36jBRYQLi7iIwq07SYkFQG8bSfdPsXAswlbBXv 22d2oMwv6iU+jpn8uBVuhzmy+n5+rqofz2CMCm+HGbSt3NhVP9/lt65q0gqjCO08faAM 5MGYYXQcAsHPemBdzqjhQCnDcW8lobka4HxIOrxxI9VWd4WwsbgBBH6ZIexP5KwdFox6 BIBA== 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=khkwpklGD+PrVZEHYMlM7uEYX4y+pMDSz5qdl2TfcH4=; b=cJxpO2ANBpLbPerIZMG6QaPbdzV3+0A4YTcx9UE8Ql14oO8wyTkE7+TjEmdOccB7RJ JEQPAgIbK4lOY0vYPky3xs3SZa2cBjEFzr0NndmnSda0PDTIJpTFKykkcJLwFmzDW8kl SgByN4goVgaHKgPpyeify02r+IRFSxbTM6XEKHZnW0tr/xtspwTkva3Y6eL45A1XlRNg /jb/EcMkc8OTr0s2wIUxo+xvKbeWJKbu4Xv0rigmD7Upx3p7sfDGXtAAGSm6tvZB3ev1 FhnmiB8EyIOsugNOZPhbEWI7l/geCj7Os6jhmck5uRIr6e8ThnJlI6i2PTZB8WIDlCEx oiPQ== X-Gm-Message-State: ALyK8tJiAb4+uZb9bWeDxNSmzeYzInWZDrok4G6Jcy1NpWMB+BOFcLP07q85jCdP9HaLhnw8UBrgufAiOnhsgw== X-Received: by 10.202.80.78 with SMTP id e75mr3644683oib.91.1467546807200; Sun, 03 Jul 2016 04:53:27 -0700 (PDT) In-Reply-To: <46690e10-1534-4f99-a40f-a148b4a21a27@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> Xref: csiph.com comp.lang.python:110992 On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D=E2=80=99Oliveiro wrote: > On Sunday, July 3, 2016 at 4:49:15 PM UTC+12, Ian wrote: >> >> On Sat, Jul 2, 2016 at 12:40 AM, Lawrence D=E2=80=99Oliveiro wrote: >>> >>> On Saturday, July 2, 2016 at 5:10:06 PM UTC+12, Ian wrote: >>>> >>>> You should use functools.wraps instead of clobbering the decorated >>>> function's name and docstring: >>> >>> Where am I doing that? >> >> Using the implementation you posted: >> >>>>> @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= ' > > That is a function that I am generating, so naturally I want to give it a= useful docstring. Am I =E2=80=9Cclobbering=E2=80=9D any objects passed in = by the caller, or returned by the caller? No, I am not. It isn't useful, though. If somebody writes a docstring for a function, it's because they want that to be the docstring for the function, not some arbitrary and vague docstring assigned by a decorator. If I type "help(my_decorator)" in the interactive interpreter, I should see what my_decorator actually does, not "generates a decorator which applies my_decorator", which just confuses with its recursiveness. The only way to find out what my_decorator actually does from the interactive interpreter would be to realize that it's been opaquely decorated and type out something like this: >>> my_decorator.__closure__[0].cell_contents.__doc__ 'Returns func unmodified.' That's far too obscure. Alternatively, one could go read the source. But if you have to go read the source to understand what a function does, then you've lost the purpose of having a docstring in the first place.