From 24ed005fb3e7ebce4c278e36017c8b9e3605e197 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Thu, 12 Feb 2026 21:32:35 +1100 Subject: [PATCH] Updated type hints --- Tests/test_file_ani.py | 6 +++++- Tests/test_file_cur.py | 1 + src/PIL/AniImagePlugin.py | 3 ++- 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/Tests/test_file_ani.py b/Tests/test_file_ani.py index b76258ef1..ab0c96ed6 100644 --- a/Tests/test_file_ani.py +++ b/Tests/test_file_ani.py @@ -4,13 +4,14 @@ from io import BytesIO import pytest -from PIL import Image +from PIL import AniImagePlugin, Image from .helper import assert_image_equal_tofile def test_aero_busy() -> None: with Image.open("Tests/images/ani/aero_busy.ani") as im: + assert isinstance(im, AniImagePlugin.AniImageFile) assert im.size == (64, 64) assert im.n_frames == 18 @@ -29,6 +30,7 @@ def test_aero_busy() -> None: def test_posy_busy() -> None: with Image.open("Tests/images/ani/posy_busy.ani") as im: + assert isinstance(im, AniImagePlugin.AniImageFile) assert im.size == (96, 96) assert im.n_frames == 77 @@ -43,6 +45,7 @@ def test_posy_busy() -> None: def test_seq_rate() -> None: with Image.open("Tests/images/ani/stopwtch.ani") as im: + assert isinstance(im, AniImagePlugin.AniImageFile) assert im.size == (32, 32) assert im.n_frames == 8 @@ -122,6 +125,7 @@ def test_save() -> None: ) with Image.open(output, formats=["ANI"]) as im: + assert isinstance(im, AniImagePlugin.AniImageFile) assert im.n_frames == 6 assert im.info["seq"] == [0, 2, 4, 1, 3, 5, 0, 1, 0, 1] assert im.info["rate"] == [1, 2, 3, 1, 2, 3, 1, 2, 3, 4] diff --git a/Tests/test_file_cur.py b/Tests/test_file_cur.py index a100f1a1b..089e094b8 100644 --- a/Tests/test_file_cur.py +++ b/Tests/test_file_cur.py @@ -59,6 +59,7 @@ def test_posy_link() -> None: assert im.getpixel((20, 20)) == (0, 0, 0, 255) assert im.getpixel((40, 40)) == (255, 255, 255, 255) + assert isinstance(im, CurImagePlugin.CurImageFile) im.size = (32, 32) im.load() assert im.getpixel((0, 0)) == (0, 0, 0, 0) diff --git a/src/PIL/AniImagePlugin.py b/src/PIL/AniImagePlugin.py index 086d7fbb1..a005191b3 100644 --- a/src/PIL/AniImagePlugin.py +++ b/src/PIL/AniImagePlugin.py @@ -283,7 +283,7 @@ def _save(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None: class AniFile: - def __init__(self, fp: BytesIO) -> None: + def __init__(self, fp: IO[bytes]) -> None: if not _accept(fp.read(4)): SyntaxError("Not an ANI file") @@ -394,6 +394,7 @@ class AniImageFile(ImageFile.ImageFile): format_description = "Windows Animated Cursor" def _open(self) -> None: + assert self.fp is not None self.ani = AniFile(self.fp) self.info["seq"] = self.ani.seq self.info["rate"] = self.ani.rate