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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for fief-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3e5cc33fff5761fcef46514fb072a8b2d40d296ef67d97bd5e812ef0451ba7da
MD5 972c81eb754c43755cd457008396c5b7
BLAKE2b-256 55880722583b559d36326bcdd861e3ad3347541e14491549143da92621e44099

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