Skip to main content

Decorator for effective parameter filtering

Project description

# FiEf, the Effective Parameter Filter

## The problem
You have this function:

def func(a, b):
# some implementation

and that configuration, extrapolated from CLI, init file and whatever:

config = {'a': 1, 'b': 'doe', 'loglevel': 'WARNING'}

Then, you can't just do that:

func(\*\*config)

Because of the expected:

TypeError: func() got an unexpected keyword argument 'loglevel'

One solution can be:

# perform an interesting and easily maintenable treatment
config_func = {
arg: val
for arg, val in config
if arg in ('a', 'b')
}
# and, finally, call that function
func(\*\*config_func)

But, as any programmer, you will use the *inspect* module, that can give you the formal parameter of *func*, and filter out unwanted effective parameters.
Just as FiEf do.

## The solution
About the previous *func*:

from fief import filter\_effective\_parameters as fief

@fief
def func(a, b):
# some implementation

# and then, use it as you always want to:
func(\*\*MY\_BIG\_CONFIG\_DICT\_WITH\_MANY\_WEIRD\_KEYS)

# or as you always do:
func(a=42, b='pip install efpafi')

# or, for a one time usage:
fief(func)(\*\*MY\_BIG\_CONFIG\_DICT\_WITH\_MANY\_WEIRD\_KEYS)

## Installation

pip install efpafi

## Licence
WTFPL.

Project details


Download files

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

Source Distribution

fief-0.1.2.tar.gz (2.3 kB view hashes)

Uploaded Source

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page