Skip to content

Commit

Permalink
New way to populate locals() for filter
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszachy committed Jun 17, 2024
1 parent 11719de commit cf0b243
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions fmf/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,11 @@ def evaluate(expression, data, _node=None):
Expects data dictionary which will be used to populate local
namespace. Used to provide flexible conditions for filtering.
"""
locals().update(data)
# Since python3.13 and https://peps.python.org/pep-0667/
_locals = copy.deepcopy(locals())
_locals.update(data)
try:
return eval(expression)
return eval(expression, globals=globals(), locals=_locals)
except NameError as error:
raise FilterError("Key is not defined in data: {}".format(error))
except KeyError as error:
Expand Down

0 comments on commit cf0b243

Please sign in to comment.