-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Added type hints to ImageSequence #7635
Added type hints to ImageSequence #7635
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Shall we add this and from typing import Self
to Image.py so mypy --strict src/PIL/ImageSequence.py
passes?
diff --git a/src/PIL/Image.py b/src/PIL/Image.py
index 1cb484b852..b121774095 100644
--- a/src/PIL/Image.py
+++ b/src/PIL/Image.py
@@ -1181,7 +1181,7 @@ class Image:
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 +2450,7 @@ class Image:
if open_fp:
fp.close()
- def seek(self, frame):
+ def seek(self, frame: int) -> None:
"""
Seeks to the given frame in this sequence file. If you seek
beyond the end of the sequence, the method raises an
@@ -2537,7 +2537,7 @@ class Image:
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`.
Wondering if we should have a TypeAlias for Image.Image
in Image.py
?
Something like this?
from typing import TypeAlias
ImageType: TypeAlias = Image.Image
Or maybe explicit is better?
Anyway, not necessary for this PR.
55a3d8b
to
f8d7503
Compare
Testing, I find that |
It turns out that TypeAlias was only added in Python 3.10 - https://docs.python.org/3/library/typing.html#typing.TypeAlias |
We should be able do it instead like
|
Ok, see what you think of #7639 |
Further thought decided against the idea of #7639 / a type alias for |
Helps #2625