mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-11-11 04:07:21 +03:00
Merge pull request #7721 from radarhere/imagemath_ops
Changed ImageMath.ops to be static
This commit is contained in:
commit
6fd85cf523
|
@ -224,10 +224,15 @@ def imagemath_convert(self: _Operand, mode: str) -> _Operand:
|
||||||
return _Operand(self.im.convert(mode))
|
return _Operand(self.im.convert(mode))
|
||||||
|
|
||||||
|
|
||||||
ops = {}
|
ops = {
|
||||||
for k, v in list(globals().items()):
|
"int": imagemath_int,
|
||||||
if k[:10] == "imagemath_":
|
"float": imagemath_float,
|
||||||
ops[k[10:]] = v
|
"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:
|
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
|
# build execution namespace
|
||||||
args = ops.copy()
|
args: dict[str, Any] = ops.copy()
|
||||||
for k in list(_dict.keys()) + list(kw.keys()):
|
for k in list(_dict.keys()) + list(kw.keys()):
|
||||||
if "__" in k or hasattr(builtins, k):
|
if "__" in k or hasattr(builtins, k):
|
||||||
msg = f"'{k}' not allowed"
|
msg = f"'{k}' not allowed"
|
||||||
|
|
Loading…
Reference in New Issue
Block a user