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


Groups > comp.lang.python > #111016

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 16:38:33 -0600
Lines 39
Message-ID <mailman.47.1467585556.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> <mailman.38.1467546815.2295.python-list@python.org> <d2f71d72-d2da-4f68-9d6a-ca059327afdd@googlegroups.com> <CALwzid=ZsBnqjcMHVU6YQ17_993z01K3wKZ2QwZb9LKF_KJt_A@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 51PfiIWWcvpVUEqmTr7ilQyC+grRm+GXvmknAmDJjxbw==
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.005
X-Spam-Evidence '*H*': 0.99; '*S*': 0.00; 'modifying': 0.07; 'caller.': 0.09; 'naturally': 0.09; 'useful,': 0.13; 'applies': 0.15; 'value.': 0.15; '2016': 0.16; 'docstring': 0.16; 'namespace.': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:parameters': 0.16; 'useless': 0.16; 'wrote:': 0.16; 'module,': 0.18; 'nested': 0.18; '>>>': 0.20; 'decorator': 0.22; 'fine,': 0.22; 'function,': 0.22; 'lawrence': 0.22; 'sorry,': 0.22; 'trying': 0.22; 'replacing': 0.23; 'sat,': 0.23; 'written': 0.24; 'header:In-Reply-To:1': 0.24; 'all.': 0.24; 'module': 0.25; "doesn't": 0.26; 'not.': 0.27; 'message-id:@mail.gmail.com': 0.27; 'function': 0.28; 'docstrings': 0.29; 'does,': 0.29; 'objects': 0.29; 'that.': 0.30; 'code': 0.30; 'somebody': 0.30; 'writes': 0.30; 'help,': 0.32; 'returned': 0.32; 'point': 0.33; 'useful': 0.33; 'purposes,': 0.33; 'though.': 0.33; 'add': 0.34; 'received:google.com': 0.35; 'something': 0.35; 'comment': 0.35; "isn't": 0.35; 'but': 0.36; 'to:addr:python-list': 0.36; 'pm,': 0.36; 'subject:: ': 0.37; 'seem': 0.37; 'no,': 0.38; "won't": 0.38; 'to:addr:python.org': 0.40; 'subject:with': 0.40; 'your': 0.60; 'within': 0.64; 'skip:\xe2 10': 0.70; 'jul': 0.72; 'decorator,': 0.84; 'to:name:python': 0.84; 'yet?': 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=CBz9xCpK6FVJgyvIAvFhAxUsaActU/8W6bNtMDJt+Ks=; b=FoBRgWrhaUdeL+zQcyBYVgOqXDNw14zg6bXS4N0FLwfIEL2Qb62bOQNreEy6DeK2Oz relT3NR6NyZ4zvfAl6OAc7ZmfMPtDEMBr+c0//5jCY/MevDEba0kH5My3VxYLYO4GkQI TBp4LH55q8lL42PNU/aOpILIh1kcKXYDwujTK3B2TgcBiv4S+24etjV1mvgx0Xj8WObA tF1j7Lmlznvaz8e2MR8ra6PvYHbbuxaf3TsEUeh7G9KHiGmrIDzUtndUTzXxGMYDeul2 DYHJIjxZdk3R3H5BIQg+ljcrwxIDEErFfOwlb23fQFQ47bxh/x3uzjxOXEsaQQtUWuVy vLQw==
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=CBz9xCpK6FVJgyvIAvFhAxUsaActU/8W6bNtMDJt+Ks=; b=lEQ1aLsj29SuR8S2/9dkuWNdUSiWOjvtw3T5OB7CHGAU1O5aezH0bzh/suQxlTIbxD NfAIfMMM8RjSbZSipQ0G7GnrpH9w/dsJxO2bq4Hbtg3zSfGFluqf1EYSziv2+zoy6nJS 8dte+5cFK8+XJPy7VHvwkEWLN1XRB4ci3rIaHszoboQyzQ9KCLvSCRpODYoqpvR91FgH 1hPjrK16TAWEy28qyiLGhaUDknB0YfG0c2frod9dOw4GVfQKhYtt2xB/8DjJuK+NzeRL XLhZ08jIV2Nw++4XtdrsvLXSwVn7yEEAVhNFxXrcAEaCN2hrKzPReE1apzdYyZzk07UQ NQlg==
X-Gm-Message-State ALyK8tK2hO0GiXtlNGwjeBMBTRWLViborsBP0IG6zNkc4VdpNJlO6xFZeubrT6W73P3xmHIUNYIFpZJnmENU3A==
X-Received by 10.157.14.86 with SMTP id n22mr392354otd.187.1467585552528; Sun, 03 Jul 2016 15:39:12 -0700 (PDT)
In-Reply-To <d2f71d72-d2da-4f68-9d6a-ca059327afdd@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 <CALwzid=ZsBnqjcMHVU6YQ17_993z01K3wKZ2QwZb9LKF_KJt_A@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> <CALwzidmn-0TyxfKxcZoNoV5CgiFuOqRS_X=W34gSn5a-NVOy_w@mail.gmail.com> <mailman.38.1467546815.2295.python-list@python.org> <d2f71d72-d2da-4f68-9d6a-ca059327afdd@googlegroups.com>
Xref csiph.com comp.lang.python:111016

Show key headers only | View raw


On Sun, Jul 3, 2016 at 3:17 PM, Lawrence D’Oliveiro
<lawrencedo99@gmail.com> wrote:
> On Sunday, July 3, 2016 at 11:53:46 PM UTC+12, Ian wrote:
>> On Sat, Jul 2, 2016 at 11:37 PM, Lawrence D’Oliveiro wrote:
>>> 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 ...
>
> Which I am not “clobbering” at all. Do you get that yet? My docstrings apply to *my* functions, not those supplied or generated by the caller.

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. If the docstring written in the code for function
m.f is x, but the value of m.f.__doc__ is actually y, then the
docstring x is, for all practical purposes, clobbered. That you're not actually
modifying the original function is irrelevant.

For the purpose of the built-in help, it's the value of m.f.__doc__
that counts. For the purpose of documentation built with pydoc, it's
the value of m.f.__doc__ that counts. If the documentation for every
decorator in a module just reads "generates a decorator which applies
<function name> to the given arguments", that's useless documentation.

Which brings me to the other half of the point I was trying to make:
your decorator_with_args doesn't even *need* a docstring. It's not
part of the public interface. As a nested function that doesn't have
its own name within the module, help() or pydoc won't even include it
in their output. If you want to put something in the code to explain
what it does, that's fine, but use a comment for that. The docstring
doesn't add any value.

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