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


Groups > comp.lang.python > #83660

Re: class-based class decorator

Path csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail
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.018
X-Spam-Evidence '*H*': 0.96; '*S*': 0.00; 'url:pypi': 0.03; 'parameters': 0.04; 'class,': 0.07; 'defaults': 0.07; 'builtin': 0.09; 'decorator': 0.09; 'sphinx': 0.09; 'wrapped': 0.09; 'python': 0.11; 'jan': 0.12; '2.7': 0.14; 'intended.': 0.16; 'subject:based': 0.16; 'subject:class': 0.16; 'wrote:': 0.18; '(not': 0.18; '(the': 0.22; '(in': 0.22; 'specify': 0.24; 'gets': 0.27; 'header:In-Reply-To:1': 0.27; 'function': 0.29; 'am,': 0.29; 'message-id:@mail.gmail.com': 0.30; 'code': 0.31; 'class': 0.32; 'regular': 0.32; 'up.': 0.33; 'url:python': 0.33; 'becomes': 0.33; 'link.': 0.33; 'problem': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'there': 0.35; 'thanks': 0.36; 'url:org': 0.36; 'needed': 0.38; 'to:addr:python-list': 0.38; '12,': 0.39; 'to:addr:python.org': 0.39; 'changed': 0.39; 'even': 0.60; 'most': 0.60; 'lost': 0.61; 'offer': 0.62; 'show': 0.63; 'information': 0.63; 'kind': 0.63; 'hoping': 0.75; '2015': 0.84; '3.4': 0.84; 'affected.': 0.84; 'code):': 0.84; 'hardly': 0.84; 'replies.': 0.84; 'package:': 0.93
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-type:content-transfer-encoding; bh=CbI6k1kXVzk9bQ5Umj4WBji+SR0d9ElAXdng+zTA87g=; b=MXK056BEsHWwummf0z4lR+FxJ2s0OSNrxf4VoCgkOzA4LIWmVm5Gm3x7XKHb066Z0K zk009kap736NT0A727AXp91FwDixJ0jQJ1z2ExPMVzYpOcd2eAqGRDlHYulr6evg4vT0 moLvfz7OBMX0e1xT4xxOQ623drY94rGlKPE5ptNWrB5kCDAW60u6Q9pH21X3a/zSQOYt zUcATgm80JaOGUxZ5zR5dQoNLCMvvmnDnx4wk1uFt/3kmOTRlA6493/qyWJfN6m123bi VZqMPx8XGxbfWCP2lNeNGqZxm0/eLYb9wwfQ1icziiURciPVj9GFHiqP76Hz3Om6MbtL f5lQ==
X-Received by 10.66.65.165 with SMTP id y5mr48851122pas.146.1421127124321; Mon, 12 Jan 2015 21:32:04 -0800 (PST)
MIME-Version 1.0
In-Reply-To <1098350771.199383.1421070276837.JavaMail.yahoo@jws10769.mail.gq1.yahoo.com>
References <CALwzidkvGKEJtZ2f2LyfA4atY0kpaQsGrCtBro5X2TyrBe98Hw@mail.gmail.com> <1098350771.199383.1421070276837.JavaMail.yahoo@jws10769.mail.gq1.yahoo.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date Mon, 12 Jan 2015 22:31:24 -0700
Subject Re: class-based class decorator
To Python <python-list@python.org>
Content-Type text/plain; charset=UTF-8
Content-Transfer-Encoding quoted-printable
X-BeenThere python-list@python.org
X-Mailman-Version 2.1.15
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>
Newsgroups comp.lang.python
Message-ID <mailman.17655.1421127132.18130.python-list@python.org> (permalink)
Lines 20
NNTP-Posting-Host 2001:888:2000:d::a6
X-Trace 1421127132 news.xs4all.nl 2896 [2001:888:2000:d::a6]:46185
X-Complaints-To abuse@xs4all.nl
Xref csiph.com comp.lang.python:83660

Show key headers only | View raw


On Jan 12, 2015 6:47 AM, "Albert-Jan Roskam" <fomcl@yahoo.com> wrote:
> Thanks for your replies. I changed it into a regular decorator (not a class decorator). It would have been even nicer if I only needed to specify it once per class, but, well, in my case this hardly matters. The code below works as intended. One problem (not specific to the code): the decorator destroys the signature: it always becomes "*args, **kwargs"). This is annoying with help(), but what worries me most is that my Sphinx documentation is also affected. The information about the defaults gets lost (the parameters are decribed in the docstring, but not the defaults). That kind of sucks. Is there a builtin way around this (in other words: I am aware of this package: https://pypi.python.org/pypi/decorator). I am hoping to get the code working on Python 2.7 and 3.3 and up.

As of (I think) 3.4 pydoc and the help() function will show you the
signature of the wrapped function as long as you use functools.wraps.
I don't know what the status is for Sphinx; all I can offer is this
stackoverflow link.

http://stackoverflow.com/questions/3687046/python-sphinx-autodoc-and-decorated-members

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


Thread

Re: class-based class decorator Ian Kelly <ian.g.kelly@gmail.com> - 2015-01-12 22:31 -0700

csiph-web