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

Uploaded Source

File details

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

File metadata

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

File hashes

Hashes for fief-0.1.3.tar.gz
Algorithm Hash digest
SHA256 01d48b22b9ed2e15d63b589ec54d9bd2d51b7eab2a3441b7481b8ef87efe4991
MD5 d796cbf1d3c84144928b33d4c2567256
BLAKE2b-256 4c2936fc6fd077fdddbeaa164746de405c4ee7059f95571d26eaa8ac6ccabfe7

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