flav-io / flavio

A Python package for flavour physics phenomenology in the Standard model and beyond
http://flav-io.github.io/
MIT License
71 stars 62 forks source link

slightly streamline wc_function_factory #53

Closed peterstangl closed 6 years ago

peterstangl commented 6 years ago

@DavidMStraub In my comment https://github.com/flav-io/flavio/pull/52#issuecomment-411542206, I wrote that the namespace dictionary would contain a '__builtins__' key. However, this is only true if one uses

exec(s, namespace)

which is equivalent to

exec(s, namespace, namespace)

and sets both the global and the local namespace to namespace. I later also realized that only the local namespace should be set to namespace and the global one to globals() like you finally did using

exec(s, globals(), namespace)

In this case, only globals() will contain '__builtins__' and there should be no need to try removing it from namespace.

I've added a warning in the case where no function is found (e.g. when one uses a lambda function and forgets to assign it to a name).

I also changed hasattr(f, '__call__') to callable(f) (see e.g. the discussion here: https://stackoverflow.com/questions/16388059/using-callablex-vs-hasattrx-call)

By the way, great idea to use an OrderedDict and use the last variable as the fit_wc_function!

coveralls commented 6 years ago

Coverage Status

Coverage decreased (-0.008%) to 90.713% when pulling a4c05c6cab17d94fdf8323c8202dafbd08a2cd4b on peterstangl:wc_function_factory into de025392266a92e436247d997f3c84600e20505d on flav-io:master.