diff --git a/Tests/test_imagegrab.py b/Tests/test_imagegrab.py index e8fd9524c..ab06f04e2 100644 --- a/Tests/test_imagegrab.py +++ b/Tests/test_imagegrab.py @@ -40,7 +40,11 @@ class TestImageGrab: @pytest.mark.skipif(Image.core.HAVE_XCB, reason="tests missing XCB") def test_grab_no_xcb(self) -> None: - if sys.platform not in ("win32", "darwin") and not shutil.which("gnome-screenshot") and not shutil.which('spectacle'): + if ( + sys.platform not in ("win32", "darwin") + and not shutil.which("gnome-screenshot") + and not shutil.which("spectacle") + ): with pytest.raises(OSError) as e: ImageGrab.grab() assert str(e.value).startswith("Pillow was built without XCB support") diff --git a/src/PIL/ImageGrab.py b/src/PIL/ImageGrab.py index 5ac0b6a21..e79b4d651 100644 --- a/src/PIL/ImageGrab.py +++ b/src/PIL/ImageGrab.py @@ -77,10 +77,7 @@ def grab( raise OSError(msg) size, data = Image.core.grabscreen_x11(display_name) except OSError: - if ( - display_name is None - and sys.platform not in ("darwin", "win32") - ): + if display_name is None and sys.platform not in ("darwin", "win32"): fh, filepath = tempfile.mkstemp(".png") os.close(fh) if shutil.which("gnome-screenshot"): @@ -89,7 +86,7 @@ def grab( subprocess.call(["spectacle", "-n", "-b", "-f", "-o", filepath]) else: os.unlink(filepath) - raise + raise im = Image.open(filepath) im.load() os.unlink(filepath)