Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.python > #110992

Re: Meta decorator with parameters, defined in explicit functions

Path csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail
From Ian Kelly <ian.g.kelly@gmail.com>
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 <mailman.38.1467546815.2295.python-list@python.org> (permalink)
References <85mvm5vrbw.fsf@benfinney.id.au> <mailman.61.1467090177.2358.python-list@python.org> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <CALwzidn8DuSo-L2UQTJ7wZfzK+eHGzgGuy_ZfHFR9v4J_NHnjQ@mail.gmail.com> <mailman.15.1467436194.2295.python-list@python.org> <facf7142-25f5-4a8b-ab37-771884ab8d64@googlegroups.com> <CALwzid=GfLU8nbc5m4M9FxEO1ObWDTcvLJ3-wJXS0=w88-v8sw@mail.gmail.com> <mailman.33.1467521333.2295.python-list@python.org> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com> <CALwzidmn-0TyxfKxcZoNoV5CgiFuOqRS_X=W34gSn5a-NVOy_w@mail.gmail.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 <ian.g.kelly@gmail.com>
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 <python-list.python.org>
List-Unsubscribe <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe>
List-Archive <http://mail.python.org/pipermail/python-list/>
List-Post <mailto:python-list@python.org>
List-Help <mailto:python-list-request@python.org?subject=help>
List-Subscribe <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe>
X-Mailman-Original-Message-ID <CALwzidmn-0TyxfKxcZoNoV5CgiFuOqRS_X=W34gSn5a-NVOy_w@mail.gmail.com>
X-Mailman-Original-References <85mvm5vrbw.fsf@benfinney.id.au> <mailman.61.1467090177.2358.python-list@python.org> <21916e7b-9e19-4cef-94e0-bac331540ca2@googlegroups.com> <CALwzidn8DuSo-L2UQTJ7wZfzK+eHGzgGuy_ZfHFR9v4J_NHnjQ@mail.gmail.com> <mailman.15.1467436194.2295.python-list@python.org> <facf7142-25f5-4a8b-ab37-771884ab8d64@googlegroups.com> <CALwzid=GfLU8nbc5m4M9FxEO1ObWDTcvLJ3-wJXS0=w88-v8sw@mail.gmail.com> <mailman.33.1467521333.2295.python-list@python.org> <46690e10-1534-4f99-a40f-a148b4a21a27@googlegroups.com>
Xref csiph.com comp.lang.python:110992

Show key headers only | View raw


On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro
<lawrencedo99@gmail.com> 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’Oliveiro 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 “clobbering” 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.

Back to comp.lang.python | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


Thread

Meta decorator with parameters, defined in explicit functions Ben Finney <ben+python@benfinney.id.au> - 2016-06-28 15:02 +1000
  Re: Meta decorator with parameters, defined in explicit functions Paul Rubin <no.email@nospam.invalid> - 2016-06-27 23:08 -0700
  Re: Meta decorator with parameters, defined in explicit functions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-28 18:39 +1000
  Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-29 19:43 -0700
    Re: Meta decorator with parameters, defined in explicit functions Steven D'Aprano <steve@pearwood.info> - 2016-06-30 13:49 +1000
    Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Peter Otten <__peter__@web.de> - 2016-06-30 09:25 +0200
      Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-30 00:43 -0700
        Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2016-06-30 18:00 +1000
        Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Peter Otten <__peter__@web.de> - 2016-06-30 10:41 +0200
    Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions dieter <dieter@handshake.de> - 2016-07-01 09:04 +0200
      Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-07-01 21:25 +0100
        Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Ben Finney <ben+python@benfinney.id.au> - 2016-07-02 11:52 +1000
        Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions dieter <dieter@handshake.de> - 2016-07-02 08:57 +0200
        Re: Fear and suspicion of lambdas, was Re: Meta decorator with parameters, defined in explicit functions Ben Finney <ben+python@benfinney.id.au> - 2016-07-02 18:00 +1000
  Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-06-29 19:50 -0700
  Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-01 15:08 -0700
    Re: Meta decorator with parameters, defined in explicit functions Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-01 23:09 -0600
      Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-01 23:40 -0700
        Re: Meta decorator with parameters, defined in explicit functions Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-02 22:48 -0600
          Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-02 22:37 -0700
            Re: Meta decorator with parameters, defined in explicit functions Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-03 05:52 -0600
              Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 14:17 -0700
                Re: Meta decorator with parameters, defined in explicit functions Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-03 16:38 -0600
                Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 16:25 -0700
                Re: Meta decorator with parameters, defined in explicit functions Chris Angelico <rosuav@gmail.com> - 2016-07-04 09:39 +1000
                Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 16:59 -0700
                Re: Meta decorator with parameters, defined in explicit functions Chris Angelico <rosuav@gmail.com> - 2016-07-04 10:06 +1000
                Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 17:23 -0700
                Re: Meta decorator with parameters, defined in explicit functions Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-03 18:01 -0600
                Re: Meta decorator with parameters, defined in explicit functions Lawrence D’Oliveiro <lawrencedo99@gmail.com> - 2016-07-03 17:06 -0700
                Re: Meta decorator with parameters, defined in explicit functions Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-03 18:20 -0600
    Re: Meta decorator with parameters, defined in explicit functions Ben Finney <ben+python@benfinney.id.au> - 2016-07-02 15:32 +1000
    Re: Meta decorator with parameters, defined in explicit functions Ian Kelly <ian.g.kelly@gmail.com> - 2016-07-01 23:53 -0600

csiph-web