From 1fa83d5b4f1bf778b0dc11e52812cbc82bf1e725 Mon Sep 17 00:00:00 2001 From: Andrew Murray Date: Mon, 25 Dec 2023 18:51:57 +1100 Subject: [PATCH] Added strict type hints --- src/PIL/Image.py | 7 ++++--- src/PIL/ImageSequence.py | 3 ++- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/PIL/Image.py b/src/PIL/Image.py index 1cb484b8528..417d7417904 100644 --- a/src/PIL/Image.py +++ b/src/PIL/Image.py @@ -40,6 +40,7 @@ from collections.abc import Callable, MutableMapping from enum import IntEnum from pathlib import Path +from typing_extensions import Self try: from defusedxml import ElementTree @@ -1181,7 +1182,7 @@ def quantize( return im - def copy(self): + def copy(self) -> Self: """ Copies this image. Use this method if you wish to paste things into an image, but still retain the original. @@ -2450,7 +2451,7 @@ def save(self, fp, format=None, **params): if open_fp: fp.close() - def seek(self, frame): + def seek(self, frame) -> Self: """ Seeks to the given frame in this sequence file. If you seek beyond the end of the sequence, the method raises an @@ -2537,7 +2538,7 @@ def getchannel(self, channel): return self._new(self.im.getband(channel)) - def tell(self): + def tell(self) -> int: """ Returns the current frame number. See :py:meth:`~PIL.Image.Image.seek`. diff --git a/src/PIL/ImageSequence.py b/src/PIL/ImageSequence.py index 2c185027630..f20ef2f7a46 100644 --- a/src/PIL/ImageSequence.py +++ b/src/PIL/ImageSequence.py @@ -17,6 +17,7 @@ from __future__ import annotations from typing import Callable +from typing_extensions import Self from . import Image @@ -48,7 +49,7 @@ def __getitem__(self, ix: int) -> Image.Image: msg = "end of sequence" raise IndexError(msg) from e - def __iter__(self) -> Iterator: + def __iter__(self) -> Self: return self def __next__(self) -> Image.Image: