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.1.tar.gz (2.4 kB view details)

Uploaded Source

File details

Details for the file fief-0.1.1.tar.gz.

File metadata

  • Download URL: fief-0.1.1.tar.gz
  • Upload date:
  • Size: 2.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for fief-0.1.1.tar.gz
Algorithm Hash digest
SHA256 acbe17d0aab603f1a3f9e1fb2839bdb460e21218eb01d5eb2caea99e8d564ebc
MD5 f63455010dec4b84b15edcef0cdfa927
BLAKE2b-256 222eb2cf1fb57aa5dc2df115b3c9d5fd223049f3b9c3abccf0c896a96a6bfd69

See more details on using hashes here.

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