From a1a687c26142e56e9622ede9bd27dee73c9673c7 Mon Sep 17 00:00:00 2001 From: Nulano Date: Mon, 1 Jan 2024 00:47:39 +0100 Subject: [PATCH] =?UTF-8?q?=EF=BB=BFadd=20type=20hints=20to=20ImageCms.get?= =?UTF-8?q?=5Fdisplay=5Fprofile?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Tests/test_imagecms.py | 7 ++++++- src/PIL/ImageCms.py | 10 +++++----- 2 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Tests/test_imagecms.py b/Tests/test_imagecms.py index c04d08806..6530dc160 100644 --- a/Tests/test_imagecms.py +++ b/Tests/test_imagecms.py @@ -4,13 +4,14 @@ import datetime import os import re import shutil +import sys from io import BytesIO from pathlib import Path from typing import Any import pytest -from PIL import Image, ImageMode, features +from PIL import Image, ImageMode, ImageWin, features from .helper import ( assert_image, @@ -213,6 +214,10 @@ def test_display_profile() -> None: # try fetching the profile for the current display device ImageCms.get_display_profile() + if sys.platform == "win32": + ImageCms.get_display_profile(ImageWin.HDC(0)) + ImageCms.get_display_profile(ImageWin.HWND(0)) + def test_lab_color_profile() -> None: ImageCms.createProfile("LAB", 5000) diff --git a/src/PIL/ImageCms.py b/src/PIL/ImageCms.py index ddfc77904..2f0f112a7 100644 --- a/src/PIL/ImageCms.py +++ b/src/PIL/ImageCms.py @@ -23,7 +23,7 @@ import operator import sys from enum import IntEnum, IntFlag from functools import reduce -from typing import Any, BinaryIO +from typing import Any, BinaryIO, SupportsInt from . import Image, __version__ from ._deprecate import deprecate @@ -341,7 +341,7 @@ class ImageCmsTransform(Image.ImagePointHandler): return im -def get_display_profile(handle=None): +def get_display_profile(handle: SupportsInt | None = None) -> ImageCmsProfile | None: """ (experimental) Fetches the profile for the current display device. @@ -351,12 +351,12 @@ def get_display_profile(handle=None): if sys.platform != "win32": return None - from . import ImageWin + from . import ImageWin # type: ignore[unused-ignore, unreachable] if isinstance(handle, ImageWin.HDC): - profile = core.get_display_profile_win32(handle, 1) + profile = core.get_display_profile_win32(int(handle), 1) else: - profile = core.get_display_profile_win32(handle or 0) + profile = core.get_display_profile_win32(int(handle or 0)) if profile is None: return None return ImageCmsProfile(profile)