Skip to content

Commit e2aa0fd

Browse files
committed
Changed ops to be static
1 parent ab1de6d commit e2aa0fd

1 file changed

Lines changed: 10 additions & 5 deletions

File tree

src/PIL/ImageMath.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,10 +224,15 @@ def imagemath_convert(self: _Operand, mode: str) -> _Operand:
224224
return _Operand(self.im.convert(mode))
225225

226226

227-
ops = {}
228-
for k, v in list(globals().items()):
229-
if k[:10] == "imagemath_":
230-
ops[k[10:]] = v
227+
ops = {
228+
"int": imagemath_int,
229+
"float": imagemath_float,
230+
"equal": imagemath_equal,
231+
"notequal": imagemath_notequal,
232+
"min": imagemath_min,
233+
"max": imagemath_max,
234+
"convert": imagemath_convert,
235+
}
231236

232237

233238
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:
244249
"""
245250

246251
# build execution namespace
247-
args = ops.copy()
252+
args: dict[str, Any] = ops.copy()
248253
for k in list(_dict.keys()) + list(kw.keys()):
249254
if "__" in k or hasattr(builtins, k):
250255
msg = f"'{k}' not allowed"

0 commit comments

Comments
 (0)