Skip to content

Commit 4301c1f

Browse files
committed
Removed ImageMath eval and options parameters
1 parent 0a29d63 commit 4301c1f

File tree

4 files changed

+22
-95
lines changed

4 files changed

+22
-95
lines changed

Tests/test_imagemath_lambda_eval.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,6 @@
22

33
from typing import Any
44

5-
import pytest
6-
75
from PIL import Image, ImageMath
86

97

@@ -55,11 +53,6 @@ def test_sanity() -> None:
5553
)
5654

5755

58-
def test_options_deprecated() -> None:
59-
with pytest.warns(DeprecationWarning, match="ImageMath.lambda_eval options"):
60-
assert ImageMath.lambda_eval(lambda args: 1, images) == 1
61-
62-
6356
def test_ops() -> None:
6457
assert pixel(ImageMath.lambda_eval(lambda args: args["A"] * -1, **images)) == "I -1"
6558

Tests/test_imagemath_unsafe_eval.py

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -35,16 +35,6 @@ def test_sanity() -> None:
3535
assert pixel(ImageMath.unsafe_eval("int(float(A)+B)", **images)) == "I 3"
3636

3737

38-
def test_eval_deprecated() -> None:
39-
with pytest.warns(DeprecationWarning, match="ImageMath.eval"):
40-
assert ImageMath.eval("1") == 1
41-
42-
43-
def test_options_deprecated() -> None:
44-
with pytest.warns(DeprecationWarning, match="ImageMath.unsafe_eval options"):
45-
assert ImageMath.unsafe_eval("1", images) == 1
46-
47-
4838
def test_ops() -> None:
4939
assert pixel(ImageMath.unsafe_eval("-A", **images)) == "I -1"
5040
assert pixel(ImageMath.unsafe_eval("+B", **images)) == "L 2"

docs/deprecations.rst

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,6 @@ Deprecated Use instead
4949
:py:data:`sys.version_info`, and ``PIL.__version__``
5050
============================================ ====================================================
5151

52-
ImageMath eval()
53-
^^^^^^^^^^^^^^^^
54-
55-
.. deprecated:: 10.3.0
56-
57-
``ImageMath.eval()`` has been deprecated. Use :py:meth:`~PIL.ImageMath.lambda_eval` or
58-
:py:meth:`~PIL.ImageMath.unsafe_eval` instead.
59-
6052
Non-image modes in ImageCms
6153
^^^^^^^^^^^^^^^^^^^^^^^^^^^
6254

@@ -94,15 +86,6 @@ ICNS (width, height, scale) sizes
9486
Setting an ICNS image size to ``(width, height, scale)`` before loading has been
9587
deprecated. Instead, ``load(scale)`` can be used.
9688

97-
ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter
98-
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
99-
100-
.. deprecated:: 11.0.0
101-
102-
The ``options`` parameter in :py:meth:`~PIL.ImageMath.lambda_eval()` and
103-
:py:meth:`~PIL.ImageMath.unsafe_eval()` has been deprecated. One or more keyword
104-
arguments can be used instead.
105-
10689
ExifTags.IFD.Makernote
10790
^^^^^^^^^^^^^^^^^^^^^^
10891

@@ -179,6 +162,16 @@ Image isImageType()
179162
``Image.isImageType(im)`` has been removed. Use ``isinstance(im, Image.Image)``
180163
instead.
181164

165+
ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter
166+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
167+
168+
.. deprecated:: 11.0.0
169+
.. versionremoved:: 12.0.0
170+
171+
The ``options`` parameter in :py:meth:`~PIL.ImageMath.lambda_eval()` and
172+
:py:meth:`~PIL.ImageMath.unsafe_eval()` has been removed. One or more keyword
173+
arguments can be used instead.
174+
182175
JpegImageFile.huffman_ac and JpegImageFile.huffman_dc
183176
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
184177

@@ -208,6 +201,15 @@ removed. They were used for obtaining raw pointers to ``ImagingCore`` internals.
208201
interact with C code, you can use ``Image.Image.getim()``, which returns a ``Capsule``
209202
object.
210203

204+
ImageMath eval()
205+
^^^^^^^^^^^^^^^^
206+
207+
.. deprecated:: 10.3.0
208+
.. versionremoved:: 12.0.0
209+
210+
``ImageMath.eval()`` has been removed. Use :py:meth:`~PIL.ImageMath.lambda_eval` or
211+
:py:meth:`~PIL.ImageMath.unsafe_eval` instead.
212+
211213
BGR;15, BGR 16 and BGR;24
212214
^^^^^^^^^^^^^^^^^^^^^^^^^
213215

src/PIL/ImageMath.py

Lines changed: 3 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121
from typing import Any, Callable
2222

2323
from . import Image, _imagingmath
24-
from ._deprecate import deprecate
2524

2625

2726
class _Operand:
@@ -233,11 +232,7 @@ def imagemath_convert(self: _Operand, mode: str) -> _Operand:
233232
}
234233

235234

236-
def lambda_eval(
237-
expression: Callable[[dict[str, Any]], Any],
238-
options: dict[str, Any] = {},
239-
**kw: Any,
240-
) -> Any:
235+
def lambda_eval(expression: Callable[[dict[str, Any]], Any], **kw: Any) -> Any:
241236
"""
242237
Returns the result of an image function.
243238
@@ -246,23 +241,13 @@ def lambda_eval(
246241
:py:func:`~PIL.Image.merge` function.
247242
248243
:param expression: A function that receives a dictionary.
249-
:param options: Values to add to the function's dictionary. Deprecated.
250-
You can instead use one or more keyword arguments.
251244
:param **kw: Values to add to the function's dictionary.
252245
:return: The expression result. This is usually an image object, but can
253246
also be an integer, a floating point value, or a pixel tuple,
254247
depending on the expression.
255248
"""
256249

257-
if options:
258-
deprecate(
259-
"ImageMath.lambda_eval options",
260-
12,
261-
"ImageMath.lambda_eval keyword arguments",
262-
)
263-
264250
args: dict[str, Any] = ops.copy()
265-
args.update(options)
266251
args.update(kw)
267252
for k, v in args.items():
268253
if isinstance(v, Image.Image):
@@ -275,11 +260,7 @@ def lambda_eval(
275260
return out
276261

277262

278-
def unsafe_eval(
279-
expression: str,
280-
options: dict[str, Any] = {},
281-
**kw: Any,
282-
) -> Any:
263+
def unsafe_eval(expression: str, **kw: Any) -> Any:
283264
"""
284265
Evaluates an image expression. This uses Python's ``eval()`` function to process
285266
the expression string, and carries the security risks of doing so. It is not
@@ -291,29 +272,19 @@ def unsafe_eval(
291272
:py:func:`~PIL.Image.merge` function.
292273
293274
:param expression: A string containing a Python-style expression.
294-
:param options: Values to add to the evaluation context. Deprecated.
295-
You can instead use one or more keyword arguments.
296275
:param **kw: Values to add to the evaluation context.
297276
:return: The evaluated expression. This is usually an image object, but can
298277
also be an integer, a floating point value, or a pixel tuple,
299278
depending on the expression.
300279
"""
301280

302-
if options:
303-
deprecate(
304-
"ImageMath.unsafe_eval options",
305-
12,
306-
"ImageMath.unsafe_eval keyword arguments",
307-
)
308-
309281
# build execution namespace
310282
args: dict[str, Any] = ops.copy()
311-
for k in [*options, *kw]:
283+
for k in kw:
312284
if "__" in k or hasattr(builtins, k):
313285
msg = f"'{k}' not allowed"
314286
raise ValueError(msg)
315287

316-
args.update(options)
317288
args.update(kw)
318289
for k, v in args.items():
319290
if isinstance(v, Image.Image):
@@ -337,32 +308,3 @@ def scan(code: CodeType) -> None:
337308
return out.im
338309
except AttributeError:
339310
return out
340-
341-
342-
def eval(
343-
expression: str,
344-
_dict: dict[str, Any] = {},
345-
**kw: Any,
346-
) -> Any:
347-
"""
348-
Evaluates an image expression.
349-
350-
Deprecated. Use lambda_eval() or unsafe_eval() instead.
351-
352-
:param expression: A string containing a Python-style expression.
353-
:param _dict: Values to add to the evaluation context. You
354-
can either use a dictionary, or one or more keyword
355-
arguments.
356-
:return: The evaluated expression. This is usually an image object, but can
357-
also be an integer, a floating point value, or a pixel tuple,
358-
depending on the expression.
359-
360-
.. deprecated:: 10.3.0
361-
"""
362-
363-
deprecate(
364-
"ImageMath.eval",
365-
12,
366-
"ImageMath.lambda_eval or ImageMath.unsafe_eval",
367-
)
368-
return unsafe_eval(expression, _dict, **kw)

0 commit comments

Comments
 (0)