felicity-lims/felicity/utils/__init__.py

47 lines
1.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 = {}
if "kwargs" in _locals.keys():
kwargs = _locals.get("kwargs")
del _locals["kwargs"]
2021-09-22 15:34:32 +08:00
if "self" in _args:
del _locals["self"]
2021-09-22 15:34:32 +08:00
if "info" in _args:
del _locals["info"]
2021-09-22 15:34:32 +08:00
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
2023-02-24 08:44:14 +08:00
def to_text(val) -> str: # noqa
return str(val)