Decorating functions without losing their signatures

Jan Riechers janpeterr at freenet.de
Wed Apr 3 01:06:11 EDT 2013


On 03.04.2013 04:05, 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; for example, I might
> want to add some keyword-only arguments to all functions that return
> instances of a particular class so that the caller can create instances
> with additional attributes. So I do something like this:
[...]
> It seems to work, but I don't like it. Does anyone know of a better way
> of doing the same thing?

Hi,

I think you might want to check out that Pycon2013 Video about Metaclass 
Prgoramming of David Beazley:
http://www.pyvideo.org/video/1716/python-3-metaprogramming

He explains how to passing attributes, such creating custom classes on 
demand and returning there signatures even when wrapped.

I think that was what you wanted to archive?

Regards
Jan



More information about the Python-list mailing list