diff --git a/Tests/test_imagemath_lambda_eval.py b/Tests/test_imagemath_lambda_eval.py index eec76118a..26c04b9a0 100644 --- a/Tests/test_imagemath_lambda_eval.py +++ b/Tests/test_imagemath_lambda_eval.py @@ -2,8 +2,6 @@ from __future__ import annotations from typing import Any -import pytest - from PIL import Image, ImageMath @@ -55,11 +53,6 @@ def test_sanity() -> None: ) -def test_options_deprecated() -> None: - with pytest.warns(DeprecationWarning, match="ImageMath.lambda_eval options"): - assert ImageMath.lambda_eval(lambda args: 1, images) == 1 - - def test_ops() -> None: assert pixel(ImageMath.lambda_eval(lambda args: args["A"] * -1, **images)) == "I -1" diff --git a/Tests/test_imagemath_unsafe_eval.py b/Tests/test_imagemath_unsafe_eval.py index 60ad6aafa..5e141a55b 100644 --- a/Tests/test_imagemath_unsafe_eval.py +++ b/Tests/test_imagemath_unsafe_eval.py @@ -35,16 +35,6 @@ def test_sanity() -> None: assert pixel(ImageMath.unsafe_eval("int(float(A)+B)", **images)) == "I 3" -def test_eval_deprecated() -> None: - with pytest.warns(DeprecationWarning, match="ImageMath.eval"): - assert ImageMath.eval("1") == 1 - - -def test_options_deprecated() -> None: - with pytest.warns(DeprecationWarning, match="ImageMath.unsafe_eval options"): - assert ImageMath.unsafe_eval("1", images) == 1 - - def test_ops() -> None: assert pixel(ImageMath.unsafe_eval("-A", **images)) == "I -1" assert pixel(ImageMath.unsafe_eval("+B", **images)) == "L 2" diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 06767c20b..9eb9650b2 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -49,14 +49,6 @@ Deprecated Use instead :py:data:`sys.version_info`, and ``PIL.__version__`` ============================================ ==================================================== -ImageMath eval() -^^^^^^^^^^^^^^^^ - -.. deprecated:: 10.3.0 - -``ImageMath.eval()`` has been deprecated. Use :py:meth:`~PIL.ImageMath.lambda_eval` or -:py:meth:`~PIL.ImageMath.unsafe_eval` instead. - Non-image modes in ImageCms ^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -94,15 +86,6 @@ ICNS (width, height, scale) sizes Setting an ICNS image size to ``(width, height, scale)`` before loading has been deprecated. Instead, ``load(scale)`` can be used. -ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ - -.. deprecated:: 11.0.0 - -The ``options`` parameter in :py:meth:`~PIL.ImageMath.lambda_eval()` and -:py:meth:`~PIL.ImageMath.unsafe_eval()` has been deprecated. One or more keyword -arguments can be used instead. - ExifTags.IFD.Makernote ^^^^^^^^^^^^^^^^^^^^^^ @@ -179,6 +162,16 @@ Image isImageType() ``Image.isImageType(im)`` has been removed. Use ``isinstance(im, Image.Image)`` instead. +ImageMath.lambda_eval and ImageMath.unsafe_eval options parameter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 11.0.0 +.. versionremoved:: 12.0.0 + +The ``options`` parameter in :py:meth:`~PIL.ImageMath.lambda_eval()` and +:py:meth:`~PIL.ImageMath.unsafe_eval()` has been removed. One or more keyword +arguments can be used instead. + JpegImageFile.huffman_ac and JpegImageFile.huffman_dc ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ @@ -208,6 +201,15 @@ removed. They were used for obtaining raw pointers to ``ImagingCore`` internals. interact with C code, you can use ``Image.Image.getim()``, which returns a ``Capsule`` object. +ImageMath eval() +^^^^^^^^^^^^^^^^ + +.. deprecated:: 10.3.0 +.. versionremoved:: 12.0.0 + +``ImageMath.eval()`` has been removed. Use :py:meth:`~PIL.ImageMath.lambda_eval` or +:py:meth:`~PIL.ImageMath.unsafe_eval` instead. + BGR;15, BGR 16 and BGR;24 ^^^^^^^^^^^^^^^^^^^^^^^^^ diff --git a/src/PIL/ImageMath.py b/src/PIL/ImageMath.py index c33809ced..d2504b1ae 100644 --- a/src/PIL/ImageMath.py +++ b/src/PIL/ImageMath.py @@ -21,7 +21,6 @@ from types import CodeType from typing import Any, Callable from . import Image, _imagingmath -from ._deprecate import deprecate class _Operand: @@ -233,11 +232,7 @@ ops = { } -def lambda_eval( - expression: Callable[[dict[str, Any]], Any], - options: dict[str, Any] = {}, - **kw: Any, -) -> Any: +def lambda_eval(expression: Callable[[dict[str, Any]], Any], **kw: Any) -> Any: """ Returns the result of an image function. @@ -246,23 +241,13 @@ def lambda_eval( :py:func:`~PIL.Image.merge` function. :param expression: A function that receives a dictionary. - :param options: Values to add to the function's dictionary. Deprecated. - You can instead use one or more keyword arguments. :param **kw: Values to add to the function's dictionary. :return: The expression result. This is usually an image object, but can also be an integer, a floating point value, or a pixel tuple, depending on the expression. """ - if options: - deprecate( - "ImageMath.lambda_eval options", - 12, - "ImageMath.lambda_eval keyword arguments", - ) - args: dict[str, Any] = ops.copy() - args.update(options) args.update(kw) for k, v in args.items(): if isinstance(v, Image.Image): @@ -275,11 +260,7 @@ def lambda_eval( return out -def unsafe_eval( - expression: str, - options: dict[str, Any] = {}, - **kw: Any, -) -> Any: +def unsafe_eval(expression: str, **kw: Any) -> Any: """ Evaluates an image expression. This uses Python's ``eval()`` function to process the expression string, and carries the security risks of doing so. It is not @@ -291,29 +272,19 @@ def unsafe_eval( :py:func:`~PIL.Image.merge` function. :param expression: A string containing a Python-style expression. - :param options: Values to add to the evaluation context. Deprecated. - You can instead use one or more keyword arguments. :param **kw: Values to add to the evaluation context. :return: The evaluated expression. This is usually an image object, but can also be an integer, a floating point value, or a pixel tuple, depending on the expression. """ - if options: - deprecate( - "ImageMath.unsafe_eval options", - 12, - "ImageMath.unsafe_eval keyword arguments", - ) - # build execution namespace args: dict[str, Any] = ops.copy() - for k in [*options, *kw]: + for k in kw: if "__" in k or hasattr(builtins, k): msg = f"'{k}' not allowed" raise ValueError(msg) - args.update(options) args.update(kw) for k, v in args.items(): if isinstance(v, Image.Image): @@ -337,32 +308,3 @@ def unsafe_eval( return out.im except AttributeError: return out - - -def eval( - expression: str, - _dict: dict[str, Any] = {}, - **kw: Any, -) -> Any: - """ - Evaluates an image expression. - - Deprecated. Use lambda_eval() or unsafe_eval() instead. - - :param expression: A string containing a Python-style expression. - :param _dict: Values to add to the evaluation context. You - can either use a dictionary, or one or more keyword - arguments. - :return: The evaluated expression. This is usually an image object, but can - also be an integer, a floating point value, or a pixel tuple, - depending on the expression. - - .. deprecated:: 10.3.0 - """ - - deprecate( - "ImageMath.eval", - 12, - "ImageMath.lambda_eval or ImageMath.unsafe_eval", - ) - return unsafe_eval(expression, _dict, **kw)