enhancing decorator signatures

  • Thread starter Diez B. Roggisch
  • Start date
D

Diez B. Roggisch

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
 
C

castironpi

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?--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top