Require fp parameter

This commit is contained in:
Andrew Murray 2024-08-29 22:15:43 +10:00
parent d00f3656a6
commit 8699f13a74
3 changed files with 5 additions and 5 deletions

View File

@ -34,7 +34,7 @@ import itertools
import os
import struct
import sys
from typing import IO, TYPE_CHECKING, Any, NamedTuple
from typing import IO, TYPE_CHECKING, Any, NamedTuple, cast
from . import Image
from ._deprecate import deprecate
@ -111,7 +111,7 @@ class ImageFile(Image.Image):
"""Base class for image file format handlers."""
def __init__(
self, fp: StrOrBytesPath | IO[bytes] | None = None, filename: str | bytes | None = None
self, fp: StrOrBytesPath | IO[bytes], filename: str | bytes | None = None
) -> None:
super().__init__()
@ -134,7 +134,7 @@ class ImageFile(Image.Image):
self._exclusive_fp = True
else:
# stream
self.fp = fp
self.fp = cast(IO[bytes], fp)
self.filename = filename if filename is not None else ""
# can be overridden
self._exclusive_fp = False

View File

@ -848,7 +848,7 @@ def _save_cjpeg(im: Image.Image, fp: IO[bytes], filename: str | bytes) -> None:
##
# Factory for making JPEG and MPO instances
def jpeg_factory(
fp: IO[bytes] | None = None, filename: str | bytes | None = None
fp: IO[bytes], filename: str | bytes | None = None
) -> JpegImageFile | MpoImageFile:
im = JpegImageFile(fp, filename)
try:

View File

@ -1126,7 +1126,7 @@ class TiffImageFile(ImageFile.ImageFile):
def __init__(
self,
fp: StrOrBytesPath | IO[bytes] | None = None,
fp: StrOrBytesPath | IO[bytes],
filename: str | bytes | None = None,
) -> None:
self.tag_v2: ImageFileDirectory_v2