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


Groups > comp.lang.python > #83660

Re: class-based class decorator

References <CALwzidkvGKEJtZ2f2LyfA4atY0kpaQsGrCtBro5X2TyrBe98Hw@mail.gmail.com> <1098350771.199383.1421070276837.JavaMail.yahoo@jws10769.mail.gq1.yahoo.com>
From Ian Kelly <ian.g.kelly@gmail.com>
Date 2015-01-12 22:31 -0700
Subject Re: class-based class decorator
Newsgroups comp.lang.python
Message-ID <mailman.17655.1421127132.18130.python-list@python.org> (permalink)

Show all headers | 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