refactor(validate.py): filter function objects by filename to ensure they are from the evaluated string

This commit is contained in:
Gabriel Almeida 2023-04-18 21:27:47 -03:00
commit a0da9c6111

View file

@ -59,7 +59,12 @@ def eval_function(function_string: str):
# Execute the code string in the new namespace
exec(function_string, namespace)
function_object = next(
(obj for name, obj in namespace.items() if isinstance(obj, types.FunctionType)),
(
obj
for name, obj in namespace.items()
if isinstance(obj, types.FunctionType)
and obj.__code__.co_filename == "<string>"
),
None,
)
if function_object is None: