|  | enhancing decorator signatures |  | |
| | | Diez B. Roggisch |  |
| Posted: Wed Aug 06, 2008 10:16 am Post subject: enhancing decorator signatures |  |
Hi,
I'm using Michele S's decorator-module to create decorators with matching signatures, for better error-catching.
However, I now want to enrich the signature of a generic wrapper so that the new function will accept more parameters (keyword only). These additional parameters are consumed by the wrapper and not passed to the decorated function.
So something like this would be cool:
@enriched_decorator("bar") def some_decorator(f, **args, **kwargs): bar = kwargs.pop("bar") return f(**args, **kwargs)
Anybody has done something like this?
Diez |
| |
| | | castironpi |  |
| Posted: Wed Aug 06, 2008 4:31 pm Post subject: Re: enhancing decorator signatures |  |
| |  | |
On Aug 6, 7:16 am, "Diez B. Roggisch" <de...@nospam.web.de> wrote:
| Quote: | Hi,
I'm using Michele S's decorator-module to create decorators with matching signatures, for better error-catching.
However, I now want to enrich the signature of a generic wrapper so that the new function will accept more parameters (keyword only). These additional parameters are consumed by the wrapper and not passed to the decorated function.
So something like this would be cool:
@enriched_decorator("bar") def some_decorator(f, **args, **kwargs): bar = kwargs.pop("bar") return f(**args, **kwargs)
Anybody has done something like this?
Diez
|
Diez,
notfound= object() @enriched_decorator("bar") def some_decorator(f, *args, **kwargs): bar = kwargs.pop("bar",notfound) return f(*args, **kwargs)
Then you would declare your function:
@some_decorator def funA( x, y, z ): do( x, y ) make( z )
And be able to call it:
funA( 0, 1, 2, bar= 'what' )
so some_decorator consumes 'bar' and preserves x, y, and z. It's working fine. What did you want to ask about?
--Roggisch has plonked me in the past. Can someone reply to this message to the group so they'll see it?-- |
| |
|
|