mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-24 17:06:16 +03:00
Added return type to ImageFile.load()
This commit is contained in:
parent
b14142462e
commit
8737709781
|
@ -218,9 +218,10 @@ if hasattr(core, "DEFAULT_STRATEGY"):
|
|||
# Registries
|
||||
|
||||
if TYPE_CHECKING:
|
||||
import mmap
|
||||
from xml.etree.ElementTree import Element
|
||||
|
||||
from . import ImageFile, ImagePalette, TiffImagePlugin
|
||||
from . import ImageFile, ImageFilter, ImagePalette, TiffImagePlugin
|
||||
from ._typing import NumpyArray, StrOrBytesPath, TypeGuard
|
||||
ID: list[str] = []
|
||||
OPEN: dict[
|
||||
|
@ -612,7 +613,7 @@ class Image:
|
|||
logger.debug("Error closing: %s", msg)
|
||||
|
||||
if getattr(self, "map", None):
|
||||
self.map = None
|
||||
self.map: mmap.mmap | None = None
|
||||
|
||||
# Instead of simply setting to None, we're setting up a
|
||||
# deferred error that will better explain that the core image
|
||||
|
@ -1336,9 +1337,6 @@ class Image:
|
|||
self.load()
|
||||
return self._new(self.im.expand(xmargin, ymargin))
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from . import ImageFilter
|
||||
|
||||
def filter(self, filter: ImageFilter.Filter | type[ImageFilter.Filter]) -> Image:
|
||||
"""
|
||||
Filters this image using the given filter. For a list of
|
||||
|
|
|
@ -174,7 +174,7 @@ class ImageFile(Image.Image):
|
|||
self.fp.close()
|
||||
self.fp = None
|
||||
|
||||
def load(self):
|
||||
def load(self) -> Image.core.PixelAccess | None:
|
||||
"""Load image data based on tile list"""
|
||||
|
||||
if self.tile is None:
|
||||
|
@ -185,7 +185,7 @@ class ImageFile(Image.Image):
|
|||
if not self.tile:
|
||||
return pixel
|
||||
|
||||
self.map = None
|
||||
self.map: mmap.mmap | None = None
|
||||
use_mmap = self.filename and len(self.tile) == 1
|
||||
# As of pypy 2.1.0, memory mapping was failing here.
|
||||
use_mmap = use_mmap and not hasattr(sys, "pypy_version_info")
|
||||
|
@ -193,17 +193,17 @@ class ImageFile(Image.Image):
|
|||
readonly = 0
|
||||
|
||||
# look for read/seek overrides
|
||||
try:
|
||||
if hasattr(self, "load_read"):
|
||||
read = self.load_read
|
||||
# don't use mmap if there are custom read/seek functions
|
||||
use_mmap = False
|
||||
except AttributeError:
|
||||
else:
|
||||
read = self.fp.read
|
||||
|
||||
try:
|
||||
if hasattr(self, "load_seek"):
|
||||
seek = self.load_seek
|
||||
use_mmap = False
|
||||
except AttributeError:
|
||||
else:
|
||||
seek = self.fp.seek
|
||||
|
||||
if use_mmap:
|
||||
|
@ -243,11 +243,8 @@ class ImageFile(Image.Image):
|
|||
# sort tiles in file order
|
||||
self.tile.sort(key=_tilesort)
|
||||
|
||||
try:
|
||||
# FIXME: This is a hack to handle TIFF's JpegTables tag.
|
||||
prefix = self.tile_prefix
|
||||
except AttributeError:
|
||||
prefix = b""
|
||||
# FIXME: This is a hack to handle TIFF's JpegTables tag.
|
||||
prefix = getattr(self, "tile_prefix", b"")
|
||||
|
||||
# Remove consecutive duplicates that only differ by their offset
|
||||
self.tile = [
|
||||
|
|
Loading…
Reference in New Issue
Block a user