_seek_check already raises an EOFError by radarhere · Pull Request #8773 · python-pillow/Pillow

_seek_check raises an EOFError if the user seeks outside of the image.

For MicImagePlugin and PsdImagePlugin, the call to that is enough, and no further error catching needs to be done to handle if seek will take us outside of the image - the EOFError would only be raised if a user deliberately changed self.images (or self.layers in the case of PsdImagePlugin).

def seek(self, frame: int) -> None:
if not self._seek_check(frame):
return
try:
filename = self.images[frame]
except IndexError as e:
msg = "no such frame"
raise EOFError(msg) from e