Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #42724
| From | Rotwang <sg552@hotmail.co.uk> |
|---|---|
| Newsgroups | comp.lang.python |
| Subject | Re: Decorating functions without losing their signatures |
| Date | 2013-04-04 02:53 +0100 |
| Organization | A noiseless patient Spider |
| Message-ID | <kjimab$87s$1@dont-email.me> (permalink) |
| References | <kjfv4f$4g1$1@dont-email.me> <515bacc8$0$29891$c3e8da3$5496439d@news.astraweb.com> |
On 03/04/2013 05:15, Steven D'Aprano wrote: > On Wed, 03 Apr 2013 02:05:31 +0100, Rotwang wrote: > >> Hi all, >> >> Here's a Python problem I've come up against and my crappy solution. >> Hopefully someone here can suggest something better. I want to decorate >> a bunch of functions with different signatures; > [...] >> After thinking about it for a while I've come up with the following >> abomination: > [...] >> It seems to work, but I don't like it. Does anyone know of a better way >> of doing the same thing? > > > Wait until Python 3.4 or 3.5 (or Python 4000?) when functools.wraps > automatically preserves the function signature? > > Alas, I think this is a hard problem to solve with current Python. You > might like to compare your solution with that of Michele Simionato's > "decorator" module: > > http://micheles.googlecode.com/hg/decorator/documentation.html > > > See this for some other ideas: > > http://numericalrecipes.wordpress.com/2009/05/25/signature-preserving- > function-decorators/ > > > > Good luck! Thanks. It'll take me a while to fully absorb the links, but it looks like both are similarly based on abusing the exec function. Thanks to Jan too.
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Decorating functions without losing their signatures Rotwang <sg552@hotmail.co.uk> - 2013-04-03 02:05 +0100
Re: Decorating functions without losing their signatures Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2013-04-03 04:15 +0000
Re: Decorating functions without losing their signatures Rotwang <sg552@hotmail.co.uk> - 2013-04-04 02:53 +0100
Re: Decorating functions without losing their signatures Jan Riechers <janpeterr@freenet.de> - 2013-04-03 08:06 +0300
Re: Decorating functions without losing their signatures Michele Simionato <michele.simionato@gmail.com> - 2013-04-03 18:18 -0700
Re: Decorating functions without losing their signatures Rotwang <sg552@hotmail.co.uk> - 2013-04-04 03:17 +0100
Re: Decorating functions without losing their signatures Rotwang <sg552@hotmail.co.uk> - 2013-04-04 02:44 +0100
csiph-web