Skip to content

Commit 6fd85cf

Browse files
authored
Merge pull request #7721 from radarhere/imagemath_ops
Changed ImageMath.ops to be static
2 parents 1d7ff59 + e2aa0fd commit 6fd85cf

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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)