From e2aa0fd4996b85334df3831c2df9bf2d5f68dadd Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Tue, 16 Jan 2024 12:55:48 +1100 Subject: [PATCH] Changed ops to be static --- src/PIL/ImageMath.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index bc3318c04..a7652f237 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -224,10 +224,15 @@ def imagemath_convert(self: _Operand, mode: str) -> _Operand: return _Operand(self.im.convert(mode)) -ops = {} -for k, v in list(globals().items()): - if k[:10] == "imagemath_": - ops[k[10:]] = v +ops = { + "int": imagemath_int, + "float": imagemath_float, + "equal": imagemath_equal, + "notequal": imagemath_notequal, + "min": imagemath_min, + "max": imagemath_max, + "convert": imagemath_convert, +} def eval(expression: str, _dict: dict[str, Any] = {}, **kw: Any) -> Any: @@ -244,7 +249,7 @@ def eval(expression: str, _dict: dict[str, Any] = {}, **kw: Any) -> Any: """ # build execution namespace - args = ops.copy() + args: dict[str, Any] = ops.copy() for k in list(_dict.keys()) + list(kw.keys()): if "__" in k or hasattr(builtins, k): msg = f"'{k}' not allowed"