felicity-lims/backend/felicity_lims/felicity/utils/__init__.py

43 lines
1 KiB
Python
Raw Normal View History

2021-09-22 15:34:32 +08:00
def get_passed_args(inspection):
2021-09-22 16:47:24 +08:00
"""
Retrieve user passed function arguments from the current frame from inspect
:param inspection: current frame arguments
:return: dict of arguments passed into function
usage:
import inspector
inspector = inspect.getargvalues(inspect.currentframe())
passed_args = get_passed_args(inspector)
2021-09-22 16:47:24 +08:00
"""
2021-09-22 15:34:32 +08:00
_args = inspection.args
_locals = inspection.locals
2021-09-27 23:45:22 +08:00
kwargs = {}
2021-09-22 15:34:32 +08:00
if 'kwargs' in _locals.keys():
kwargs = _locals.get('kwargs')
del _locals['kwargs']
if 'self' in _args:
del _locals['self']
if 'info' in _args:
del _locals['info']
final = {**kwargs, **_locals}
# [(arg,args.locals[arg]) for arg in args.args]
2021-12-06 00:37:33 +08:00
# print(f"Func Inspector: {final}")
2021-09-22 15:34:32 +08:00
return final
def has_value_or_is_truthy(val) -> bool: # noqa
if isinstance(val, bool):
return True
if not val:
return False
if isinstance(val, str):
if not val.strip():
return False
return True