From ddec690625246a04c97ac64fe8da69c9d5400793 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 22 Jun 2024 17:02:19 +1000 Subject: [PATCH 1/3] Removed ignores --- src/PIL/ImageGrab.py | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py index 96a28bb3570..aa53abd2084 100644 --- a/src/PIL/ImageGrab.py +++ b/src/PIL/ImageGrab.py @@ -22,7 +22,6 @@ import subprocess import sys import tempfile -from typing import Union, cast from . import Image @@ -70,15 +69,15 @@ def grab( left, top, right, bottom = bbox im = im.crop((left - x0, top - y0, right - x0, bottom - y0)) return im - xdisplay = cast(Union[str, None], xdisplay) # type: ignore[redundant-cast, unused-ignore] + display_name: str | None = xdisplay try: if not Image.core.HAVE_XCB: msg = "Pillow was built without XCB support" raise OSError(msg) - size, data = Image.core.grabscreen_x11(xdisplay) + size, data = Image.core.grabscreen_x11(display_name) except OSError: if ( - xdisplay is None + display_name is None and sys.platform not in ("darwin", "win32") and shutil.which("gnome-screenshot") ): From 95066b10fd32075f105c90af64a965f73c4ebfe9 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Sat, 22 Jun 2024 17:02:28 +1000 Subject: [PATCH 2/3] Added type hints to tests --- Tests/test_imagegrab.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index e23adeb7083..5dfa51697c2 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -89,6 +89,7 @@ def test_grabclipboard_file(self) -> None: p.communicate() im = ImageGrab.grabclipboard() + assert isinstance(im, list) assert len(im) == 1 assert os.path.samefile(im[0], "Tests/images/hopper.gif") @@ -105,6 +106,7 @@ def test_grabclipboard_png(self) -> None: p.communicate() im = ImageGrab.grabclipboard() + assert isinstance(im, Image.Image) assert_image_equal_tofile(im, "Tests/images/hopper.png") @pytest.mark.skipif( @@ -120,6 +122,7 @@ def test_grabclipboard_wl_clipboard(self, ext: str) -> None: with open(image_path, "rb") as fp: subprocess.call(["wl-copy"], stdin=fp) im = ImageGrab.grabclipboard() + assert isinstance(im, Image.Image) assert_image_equal_tofile(im, image_path) @pytest.mark.skipif( From 077f1d08a9b8178845a22aac7a0fbac73a288da3 Mon Sep 17 00:00:00 2001 From: Andrew Murray <3112309+radarhere@users.noreply.github.com> Date: Tue, 25 Jun 2024 07:13:17 +1000 Subject: [PATCH 3/3] Added comment MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Ondrej Baranovič --- src/PIL/ImageGrab.py | 1 + 1 file changed, 1 insertion(+) diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py index aa53abd2084..e27ca7e5033 100644 --- a/src/PIL/ImageGrab.py +++ b/src/PIL/ImageGrab.py @@ -69,6 +69,7 @@ def grab( left, top, right, bottom = bbox im = im.crop((left - x0, top - y0, right - x0, bottom - y0)) return im + # Cast to Optional[str] needed for Windows and macOS. display_name: str | None = xdisplay try: if not Image.core.HAVE_XCB: