Skip to content

Commit a1a687c

Browse files
committed
add type hints to ImageCms.get_display_profile
1 parent 0630ef0 commit a1a687c

2 files changed

Lines changed: 11 additions & 6 deletions

File tree

Tests/test_imagecms.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,14 @@
44
import os
55
import re
66
import shutil
7+
import sys
78
from io import BytesIO
89
from pathlib import Path
910
from typing import Any
1011

1112
import pytest
1213

13-
from PIL import Image, ImageMode, features
14+
from PIL import Image, ImageMode, ImageWin, features
1415

1516
from .helper import (
1617
assert_image,
@@ -213,6 +214,10 @@ def test_display_profile() -> None:
213214
# try fetching the profile for the current display device
214215
ImageCms.get_display_profile()
215216

217+
if sys.platform == "win32":
218+
ImageCms.get_display_profile(ImageWin.HDC(0))
219+
ImageCms.get_display_profile(ImageWin.HWND(0))
220+
216221

217222
def test_lab_color_profile() -> None:
218223
ImageCms.createProfile("LAB", 5000)

src/PIL/ImageCms.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
import sys
2424
from enum import IntEnum, IntFlag
2525
from functools import reduce
26-
from typing import Any, BinaryIO
26+
from typing import Any, BinaryIO, SupportsInt
2727

2828
from . import Image, __version__
2929
from ._deprecate import deprecate
@@ -341,7 +341,7 @@ def apply_in_place(self, im: Image.Image) -> Image.Image:
341341
return im
342342

343343

344-
def get_display_profile(handle=None):
344+
def get_display_profile(handle: SupportsInt | None = None) -> ImageCmsProfile | None:
345345
"""
346346
(experimental) Fetches the profile for the current display device.
347347
@@ -351,12 +351,12 @@ def get_display_profile(handle=None):
351351
if sys.platform != "win32":
352352
return None
353353

354-
from . import ImageWin
354+
from . import ImageWin # type: ignore[unused-ignore, unreachable]
355355

356356
if isinstance(handle, ImageWin.HDC):
357-
profile = core.get_display_profile_win32(handle, 1)
357+
profile = core.get_display_profile_win32(int(handle), 1)
358358
else:
359-
profile = core.get_display_profile_win32(handle or 0)
359+
profile = core.get_display_profile_win32(int(handle or 0))
360360
if profile is None:
361361
return None
362362
return ImageCmsProfile(profile)

0 commit comments

Comments
 (0)