473,324 Members | 2,548 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,324 software developers and data experts.

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
Aug 6 '08 #1
1 950
On Aug 6, 7:16*am, "Diez B. Roggisch" <de...@nospam.web.dewrote:
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?--
Aug 6 '08 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

30
by: Ron_Adam | last post by:
I was having some difficulty figuring out just what was going on with decorators. So after a considerable amount of experimenting I was able to take one apart in a way. It required me to take a...
22
by: Ron_Adam | last post by:
Hi, Thanks again for all the helping me understand the details of decorators. I put together a class to create decorators that could make them a lot easier to use. It still has a few glitches...
20
by: Chris | last post by:
I'm not sure if this has been done before, but I couldn't easily find any prior work on Google, so here I present a simple decorator for documenting and verifying the type of function arguments....
4
by: thomas.karolski | last post by:
Hi, I would like to create a Decorator metaclass, which automatically turns a class which inherits from the "Decorator" type into a decorator. A decorator in this case, is simply a class which...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.