Skip to main content
Join the official 2019 Python Developers SurveyStart the survey!

Decorator utils. Currently 'paremetrized': a decorator to enable flat decorators: call the wrapped func straight from your decorator body

Project description

## extradeco

### parametrized(flat_decorator)

A super-flatter decorator decorator!

One is supposed to decorate what would be your inner "wrapper" function in a decorator with
"parametrized". That "wrapper" can now be used as a paramterized decorator with extra parameters
whatever parameters it takes when decorating are passed along with the func object when the func itself
is called - "*args" and "**kwargs" arguments should be passed down in the call to the original `func`.

### Example of use:

Create a flat decorator which wants parameters by doing:

```
from extradeco import paremetrized

@parametrized
def ubberlog(func, loglevel, *args, **kw):
if loglevel > 2:
print ("doing things")
if loglevel > 1:
print("doing less things")
# Line that calls the original function directly on the decorator body
result = func(*args, **kw)
if loglevel:
print("function returned", result)
return result
```

And then, the new logger decorator is ready to be used like this:


```

@ubberlog(2)
def soma(a, b):
return a + b


@ubberlog(1)
def s1(a, b):
return a + b
```

### Warning
For now, the parameter names in the decorator cannot match any parameter name in the final decorated function.
It is advised that you prefix the parameter names in the decorator with somethign that won't be present in the decorated functions.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for extradeco, version 0.1.1
Filename, size File type Python version Upload date Hashes
Filename, size extradeco-0.1.1.tar.gz (5.6 kB) File type Source Python version None Upload date Hashes View hashes

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN SignalFx SignalFx Supporter DigiCert DigiCert EV certificate StatusPage StatusPage Status page