From 4b90888a7db8953f3f56bf166672661b93343f5a Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 20 Oct 2025 19:38:29 +1100 Subject: [PATCH] Added type hints --- Tests/test_file_gbr.py | 2 +- Tests/test_file_iptc.py | 2 +- src/PIL/ImageText.py | 5 ++--- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Tests/test_file_gbr.py b/Tests/test_file_gbr.py index b8851d82b..d89ef0583 100644 --- a/Tests/test_file_gbr.py +++ b/Tests/test_file_gbr.py @@ -33,7 +33,7 @@ def test_multiple_load_operations() -> None: assert_image_equal_tofile(im, "Tests/images/gbr.png") -def create_gbr_image(info: dict[str, int] = {}, magic_number=b"") -> BytesIO: +def create_gbr_image(info: dict[str, int] = {}, magic_number: bytes = b"") -> BytesIO: return BytesIO( b"".join( _binary.o32be(i) diff --git a/Tests/test_file_iptc.py b/Tests/test_file_iptc.py index 5a8aaa3ef..0376b9997 100644 --- a/Tests/test_file_iptc.py +++ b/Tests/test_file_iptc.py @@ -12,7 +12,7 @@ TEST_FILE = "Tests/images/iptc.jpg" def create_iptc_image(info: dict[str, int] = {}) -> BytesIO: - def field(tag, value): + def field(tag: tuple[int, int], value: bytes) -> bytes: return bytes((0x1C,) + tag + (0, len(value))) + value data = field((3, 60), bytes((info.get("layers", 1), info.get("component", 0)))) diff --git a/src/PIL/ImageText.py b/src/PIL/ImageText.py index c74570e69..6c5a8a8a3 100644 --- a/src/PIL/ImageText.py +++ b/src/PIL/ImageText.py @@ -88,7 +88,7 @@ class Text: else: return "L" - def get_length(self): + def get_length(self) -> float: """ Returns length (in pixels with 1/64 precision) of text. @@ -130,8 +130,7 @@ class Text: :return: Either width for horizontal text, or height for vertical text. """ - split_character = "\n" if isinstance(self.text, str) else b"\n" - if split_character in self.text: + if "\n" in self.text if isinstance(self.text, str) else b"\n" in self.text: msg = "can't measure length of multiline text" raise ValueError(msg) return self.font.getlength(