Google
 
Webnews.only-4-geeks.com
Interesting places
news.only-4-geeks.com Forum Index » Python

enhancing decorator signatures

 
Jump to:  
 
Diez B. Roggisch
PostPosted: 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
PostPosted: 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?--
 

Page 1 of 1 .:.

Google
 
Webnews.only-4-geeks.com

Windows Update | C++ | C | PHP | JavaScript | Photoshop | Programming | Windows 2000 | Python | Windows XP | Object | Flash | Flash - ActionScript | Paint Shop Pro | Excel | PowerPoint | Access | Word | Windows 98 | Internet Explorer 6.0 | CorelDraw12 | Java | XML | asm x86 | Linux Mandrake | Linux RedHat | Outlook |  | news from newsgroups |_ | s

Web Templates

Awesome Website Templates ©

Napoles hoteles Stwarzanie ƛwiata - MiƂosz CzesƂaw biĆŒuteria męska tv za darmo In vitro