From e225f9f589e07d46ad5d1f79e7c233addf9c3836 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 10 Jun 2024 11:50:13 +1000 Subject: [PATCH 1/3] Deprecate ImageDraw.getdraw hints argument --- Tests/test_imagedraw.py | 5 +++++ docs/deprecations.rst | 7 +++++++ docs/releasenotes/10.4.0.rst | 5 +++++ src/PIL/ImageDraw.py | 24 ++++++++---------------- 4 files changed, 25 insertions(+), 16 deletions(-) diff --git a/Tests/test_imagedraw.py b/Tests/test_imagedraw.py index c221fe008..61d7b5c6a 100644 --- a/Tests/test_imagedraw.py +++ b/Tests/test_imagedraw.py @@ -1624,3 +1624,8 @@ def test_incorrectly_ordered_coordinates(xy: tuple[int, int, int, int]) -> None: draw.rectangle(xy) with pytest.raises(ValueError): draw.rounded_rectangle(xy) + + +def test_getdraw(): + with pytest.warns(DeprecationWarning): + ImageDraw.getdraw(None, []) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index b2cd968fe..8a03d858c 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -115,6 +115,13 @@ Support for LibTIFF earlier than 4 Support for LibTIFF earlier than version 4 has been deprecated. Upgrade to a newer version of LibTIFF instead. +ImageDraw.getdraw hints argument +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. deprecated:: 10.4.0 + +The ``hints`` argument in :py:meth:`~PIL.ImageDraw.getdraw()` has been deprecated. + Removed features ---------------- diff --git a/docs/releasenotes/10.4.0.rst b/docs/releasenotes/10.4.0.rst index e0d695a8b..8c49e0842 100644 --- a/docs/releasenotes/10.4.0.rst +++ b/docs/releasenotes/10.4.0.rst @@ -34,6 +34,11 @@ Support for LibTIFF earlier than 4 Support for LibTIFF earlier than version 4 has been deprecated. Upgrade to a newer version of LibTIFF instead. +ImageDraw.getdraw hints argument +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +The ``hints`` argument in :py:meth:`~PIL.ImageDraw.getdraw()` has been deprecated. + API Changes =========== diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index 73ed3d4a9..ec15b535f 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -37,6 +37,7 @@ import struct from typing import TYPE_CHECKING, AnyStr, Sequence, cast from . import Image, ImageColor +from ._deprecate import deprecate from ._typing import Coords """ @@ -902,26 +903,17 @@ except AttributeError: def getdraw(im=None, hints=None): """ - (Experimental) A more advanced 2D drawing interface for PIL images, - based on the WCK interface. - :param im: The image to draw in. - :param hints: An optional list of hints. + :param hints: An optional list of hints. Deprecated. :returns: A (drawing context, drawing resource factory) tuple. """ - # FIXME: this needs more work! - # FIXME: come up with a better 'hints' scheme. - handler = None - if not hints or "nicest" in hints: - try: - from . import _imagingagg as handler - except ImportError: - pass - if handler is None: - from . import ImageDraw2 as handler + if hints is not None: + deprecate("'hints' argument", 12) + from . import ImageDraw2 + if im: - im = handler.Draw(im) - return im, handler + im = ImageDraw2.Draw(im) + return im, ImageDraw2 def floodfill( From 9f831317fe98633214ad0266417d349b44e5d6bf Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:47:18 +1000 Subject: [PATCH 2/3] Updated text Co-authored-by: Hugo van Kemenade <1324225+hugovk@users.noreply.github.com> --- docs/deprecations.rst | 6 +++--- docs/releasenotes/10.4.0.rst | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/docs/deprecations.rst b/docs/deprecations.rst index 8a03d858c..627672e1f 100644 --- a/docs/deprecations.rst +++ b/docs/deprecations.rst @@ -115,12 +115,12 @@ Support for LibTIFF earlier than 4 Support for LibTIFF earlier than version 4 has been deprecated. Upgrade to a newer version of LibTIFF instead. -ImageDraw.getdraw hints argument -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +ImageDraw.getdraw hints parameter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ .. deprecated:: 10.4.0 -The ``hints`` argument in :py:meth:`~PIL.ImageDraw.getdraw()` has been deprecated. +The ``hints`` parameter in :py:meth:`~PIL.ImageDraw.getdraw()` has been deprecated. Removed features ---------------- diff --git a/docs/releasenotes/10.4.0.rst b/docs/releasenotes/10.4.0.rst index 8c49e0842..44727efd4 100644 --- a/docs/releasenotes/10.4.0.rst +++ b/docs/releasenotes/10.4.0.rst @@ -34,10 +34,10 @@ Support for LibTIFF earlier than 4 Support for LibTIFF earlier than version 4 has been deprecated. Upgrade to a newer version of LibTIFF instead. -ImageDraw.getdraw hints argument -^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ +ImageDraw.getdraw hints parameter +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ -The ``hints`` argument in :py:meth:`~PIL.ImageDraw.getdraw()` has been deprecated. +The ``hints`` parameter in :py:meth:`~PIL.ImageDraw.getdraw()` has been deprecated. API Changes =========== From 4679e4bf9e542ffae8c81e68603d5c944108389f Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Mon, 10 Jun 2024 16:47:52 +1000 Subject: [PATCH 3/3] Updated deprecation warning --- src/PIL/ImageDraw.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/PIL/ImageDraw.py b/src/PIL/ImageDraw.py index ec15b535f..23d7e6973 100644 --- a/src/PIL/ImageDraw.py +++ b/src/PIL/ImageDraw.py @@ -908,7 +908,7 @@ def getdraw(im=None, hints=None): :returns: A (drawing context, drawing resource factory) tuple. """ if hints is not None: - deprecate("'hints' argument", 12) + deprecate("'hints' parameter", 12) from . import ImageDraw2 if im: