mirror of
				https://github.com/python-pillow/Pillow.git
				synced 2025-11-04 01:47:47 +03:00 
			
		
		
		
	Merge pull request #7635 from radarhere/type_hints_imagesequence
This commit is contained in:
		
						commit
						fbecf7790b
					
				| 
						 | 
				
			
			@ -1181,7 +1181,7 @@ class Image:
 | 
			
		|||
 | 
			
		||||
        return im
 | 
			
		||||
 | 
			
		||||
    def copy(self):
 | 
			
		||||
    def copy(self) -> Image:
 | 
			
		||||
        """
 | 
			
		||||
        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) -> Image:
 | 
			
		||||
        """
 | 
			
		||||
        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`.
 | 
			
		||||
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -16,6 +16,10 @@
 | 
			
		|||
##
 | 
			
		||||
from __future__ import annotations
 | 
			
		||||
 | 
			
		||||
from typing import Callable
 | 
			
		||||
 | 
			
		||||
from . import Image
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
class Iterator:
 | 
			
		||||
    """
 | 
			
		||||
| 
						 | 
				
			
			@ -29,14 +33,14 @@ class Iterator:
 | 
			
		|||
    :param im: An image object.
 | 
			
		||||
    """
 | 
			
		||||
 | 
			
		||||
    def __init__(self, im):
 | 
			
		||||
    def __init__(self, im: Image.Image):
 | 
			
		||||
        if not hasattr(im, "seek"):
 | 
			
		||||
            msg = "im must have seek method"
 | 
			
		||||
            raise AttributeError(msg)
 | 
			
		||||
        self.im = im
 | 
			
		||||
        self.position = getattr(self.im, "_min_frame", 0)
 | 
			
		||||
 | 
			
		||||
    def __getitem__(self, ix):
 | 
			
		||||
    def __getitem__(self, ix: int) -> Image.Image:
 | 
			
		||||
        try:
 | 
			
		||||
            self.im.seek(ix)
 | 
			
		||||
            return self.im
 | 
			
		||||
| 
						 | 
				
			
			@ -44,10 +48,10 @@ class Iterator:
 | 
			
		|||
            msg = "end of sequence"
 | 
			
		||||
            raise IndexError(msg) from e
 | 
			
		||||
 | 
			
		||||
    def __iter__(self):
 | 
			
		||||
    def __iter__(self) -> Iterator:
 | 
			
		||||
        return self
 | 
			
		||||
 | 
			
		||||
    def __next__(self):
 | 
			
		||||
    def __next__(self) -> Image.Image:
 | 
			
		||||
        try:
 | 
			
		||||
            self.im.seek(self.position)
 | 
			
		||||
            self.position += 1
 | 
			
		||||
| 
						 | 
				
			
			@ -57,7 +61,10 @@ class Iterator:
 | 
			
		|||
            raise StopIteration(msg) from e
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
def all_frames(im, func=None):
 | 
			
		||||
def all_frames(
 | 
			
		||||
    im: Image.Image | list[Image.Image],
 | 
			
		||||
    func: Callable[[Image.Image], Image.Image] | None = None,
 | 
			
		||||
) -> list[Image.Image]:
 | 
			
		||||
    """
 | 
			
		||||
    Applies a given function to all frames in an image or a list of images.
 | 
			
		||||
    The frames are returned as a list of separate images.
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
		Loading…
	
		Reference in New Issue
	
	Block a user