Python **kwargs, control correctness of parameters

Viewed 70

I'm looking for the best practice to control the insertion of parameters in python functions that make use of **kwargs. for example the possible arguments of **kwargs could be cw and/or latlon and that's it. I make use of a rudimentary list to check if the parameter present in **kwargs is correct.

pr_label = ['PAN', 'SWIR', 'VNIR']
key_fun_get = ['cw', 'latlon']

def get(pr_type: str, **kwargs):
        if not isinstance(pr_type, str) or str(pr_type).upper() not in pr_label:
            raise TypeError('pr_type: {0}, not valid.'.format(pr_type))
        if bool(kwargs):
            keys = list(kwargs.keys())
            for k in keys:
                if k.lower() not in key_fun_get:
                    raise TypeError('parameter: {0}, not valid.'.format(k))
        # TODO: foo
0 Answers
Related