mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Merge pull request #8051 from radarhere/type_hint
This commit is contained in:
commit
1cdbb5f34f
|
@ -37,7 +37,7 @@ class BufrStubImageFile(ImageFile.StubImageFile):
|
|||
format = "BUFR"
|
||||
format_description = "BUFR"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
offset = self.fp.tell()
|
||||
|
||||
if not _accept(self.fp.read(4)):
|
||||
|
|
|
@ -37,7 +37,7 @@ class CurImageFile(BmpImagePlugin.BmpImageFile):
|
|||
format = "CUR"
|
||||
format_description = "Windows Cursor"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
offset = self.fp.tell()
|
||||
|
||||
# check magic
|
||||
|
|
|
@ -237,7 +237,7 @@ class FpxImageFile(ImageFile.ImageFile):
|
|||
|
||||
return ImageFile.ImageFile.load(self)
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
self.ole.close()
|
||||
super().close()
|
||||
|
||||
|
|
|
@ -71,7 +71,7 @@ class FtexImageFile(ImageFile.ImageFile):
|
|||
format = "FTEX"
|
||||
format_description = "Texture File Format (IW2:EOC)"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
if not _accept(self.fp.read(4)):
|
||||
msg = "not an FTEX file"
|
||||
raise SyntaxError(msg)
|
||||
|
|
|
@ -41,7 +41,7 @@ class GbrImageFile(ImageFile.ImageFile):
|
|||
format = "GBR"
|
||||
format_description = "GIMP brush file"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
header_size = i32(self.fp.read(4))
|
||||
if header_size < 20:
|
||||
msg = "not a GIMP brush"
|
||||
|
|
|
@ -37,7 +37,7 @@ class GribStubImageFile(ImageFile.StubImageFile):
|
|||
format = "GRIB"
|
||||
format_description = "GRIB"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
offset = self.fp.tell()
|
||||
|
||||
if not _accept(self.fp.read(8)):
|
||||
|
|
|
@ -119,7 +119,7 @@ class ImImageFile(ImageFile.ImageFile):
|
|||
format_description = "IFUNC Image Memory"
|
||||
_close_exclusive_fp_after_loading = False
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
# Quick rejection: if there's not an LF among the first
|
||||
# 100 bytes, this is (probably) not a text header.
|
||||
|
||||
|
|
|
@ -128,7 +128,7 @@ class PhotoImage:
|
|||
if image:
|
||||
self.paste(image)
|
||||
|
||||
def __del__(self):
|
||||
def __del__(self) -> None:
|
||||
name = self.__photo.name
|
||||
self.__photo.name = None
|
||||
try:
|
||||
|
@ -219,7 +219,7 @@ class BitmapImage:
|
|||
kw["data"] = image.tobitmap()
|
||||
self.__photo = tkinter.BitmapImage(**kw)
|
||||
|
||||
def __del__(self):
|
||||
def __del__(self) -> None:
|
||||
name = self.__photo.name
|
||||
self.__photo.name = None
|
||||
try:
|
||||
|
|
|
@ -215,7 +215,7 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
|||
format = "JPEG2000"
|
||||
format_description = "JPEG 2000 (ISO 15444)"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
sig = self.fp.read(4)
|
||||
if sig == b"\xff\x4f\xff\x51":
|
||||
self.codec = "j2k"
|
||||
|
@ -267,7 +267,7 @@ class Jpeg2KImageFile(ImageFile.ImageFile):
|
|||
)
|
||||
]
|
||||
|
||||
def _parse_comment(self):
|
||||
def _parse_comment(self) -> None:
|
||||
hdr = self.fp.read(2)
|
||||
length = _binary.i16be(hdr)
|
||||
self.fp.seek(length - 2, os.SEEK_CUR)
|
||||
|
|
|
@ -462,7 +462,7 @@ class JpegImageFile(ImageFile.ImageFile):
|
|||
box = (0, 0, original_size[0] / scale, original_size[1] / scale)
|
||||
return self.mode, box
|
||||
|
||||
def load_djpeg(self):
|
||||
def load_djpeg(self) -> None:
|
||||
# ALTERNATIVE: handle JPEGs via the IJG command line utilities
|
||||
|
||||
f, path = tempfile.mkstemp()
|
||||
|
|
|
@ -100,7 +100,7 @@ class MpoImageFile(JpegImagePlugin.JpegImageFile):
|
|||
format_description = "MPO (CIPA DC-007)"
|
||||
_close_exclusive_fp_after_loading = False
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
self.fp.seek(0) # prep the fp in order to pass the JPEG test
|
||||
JpegImagePlugin.JpegImageFile._open(self)
|
||||
self._after_jpeg_open()
|
||||
|
|
|
@ -54,7 +54,7 @@ class PSDraw:
|
|||
self.fp.write(b"%%EndProlog\n")
|
||||
self.isofont = {}
|
||||
|
||||
def end_document(self):
|
||||
def end_document(self) -> None:
|
||||
"""Ends printing. (Write PostScript DSC footer.)"""
|
||||
self.fp.write(b"%%EndDocument\nrestore showpage\n%%End\n")
|
||||
if hasattr(self.fp, "flush"):
|
||||
|
|
|
@ -409,28 +409,28 @@ class PdfParser:
|
|||
self.close()
|
||||
return False # do not suppress exceptions
|
||||
|
||||
def start_writing(self):
|
||||
def start_writing(self) -> None:
|
||||
self.close_buf()
|
||||
self.seek_end()
|
||||
|
||||
def close_buf(self):
|
||||
def close_buf(self) -> None:
|
||||
try:
|
||||
self.buf.close()
|
||||
except AttributeError:
|
||||
pass
|
||||
self.buf = None
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
if self.should_close_buf:
|
||||
self.close_buf()
|
||||
if self.f is not None and self.should_close_file:
|
||||
self.f.close()
|
||||
self.f = None
|
||||
|
||||
def seek_end(self):
|
||||
def seek_end(self) -> None:
|
||||
self.f.seek(0, os.SEEK_END)
|
||||
|
||||
def write_header(self):
|
||||
def write_header(self) -> None:
|
||||
self.f.write(b"%PDF-1.4\n")
|
||||
|
||||
def write_comment(self, s):
|
||||
|
@ -450,7 +450,7 @@ class PdfParser:
|
|||
)
|
||||
return self.root_ref
|
||||
|
||||
def rewrite_pages(self):
|
||||
def rewrite_pages(self) -> None:
|
||||
pages_tree_nodes_to_delete = []
|
||||
for i, page_ref in enumerate(self.orig_pages):
|
||||
page_info = self.cached_objects[page_ref]
|
||||
|
@ -529,7 +529,7 @@ class PdfParser:
|
|||
f.write(b"endobj\n")
|
||||
return ref
|
||||
|
||||
def del_root(self):
|
||||
def del_root(self) -> None:
|
||||
if self.root_ref is None:
|
||||
return
|
||||
del self.xref_table[self.root_ref.object_id]
|
||||
|
@ -547,7 +547,7 @@ class PdfParser:
|
|||
except ValueError: # cannot mmap an empty file
|
||||
return b""
|
||||
|
||||
def read_pdf_info(self):
|
||||
def read_pdf_info(self) -> None:
|
||||
self.file_size_total = len(self.buf)
|
||||
self.file_size_this = self.file_size_total - self.start_offset
|
||||
self.read_trailer()
|
||||
|
|
|
@ -179,7 +179,7 @@ class ChunkStream:
|
|||
def __exit__(self, *args):
|
||||
self.close()
|
||||
|
||||
def close(self):
|
||||
def close(self) -> None:
|
||||
self.queue = self.fp = None
|
||||
|
||||
def push(self, cid, pos, length):
|
||||
|
@ -370,14 +370,14 @@ class PngStream(ChunkStream):
|
|||
)
|
||||
raise ValueError(msg)
|
||||
|
||||
def save_rewind(self):
|
||||
def save_rewind(self) -> None:
|
||||
self.rewind_state = {
|
||||
"info": self.im_info.copy(),
|
||||
"tile": self.im_tile,
|
||||
"seq_num": self._seq_num,
|
||||
}
|
||||
|
||||
def rewind(self):
|
||||
def rewind(self) -> None:
|
||||
self.im_info = self.rewind_state["info"].copy()
|
||||
self.im_tile = self.rewind_state["tile"]
|
||||
self._seq_num = self.rewind_state["seq_num"]
|
||||
|
|
|
@ -70,7 +70,7 @@ class PyAccess:
|
|||
# logger.debug("%s", vals)
|
||||
self._post_init()
|
||||
|
||||
def _post_init(self):
|
||||
def _post_init(self) -> None:
|
||||
pass
|
||||
|
||||
def __setitem__(self, xy, color):
|
||||
|
|
|
@ -21,7 +21,7 @@ class QoiImageFile(ImageFile.ImageFile):
|
|||
format = "QOI"
|
||||
format_description = "Quite OK Image"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
if not _accept(self.fp.read(4)):
|
||||
msg = "not a QOI file"
|
||||
raise SyntaxError(msg)
|
||||
|
|
|
@ -43,7 +43,7 @@ class WebPImageFile(ImageFile.ImageFile):
|
|||
__loaded = 0
|
||||
__logical_frame = 0
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
if not _webp.HAVE_WEBPANIM:
|
||||
# Legacy mode
|
||||
data, width, height, self._mode, icc_profile, exif = _webp.WebPDecode(
|
||||
|
|
|
@ -79,7 +79,7 @@ class WmfStubImageFile(ImageFile.StubImageFile):
|
|||
format = "WMF"
|
||||
format_description = "Windows Metafile"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
self._inch = None
|
||||
|
||||
# check placable header
|
||||
|
|
|
@ -36,7 +36,7 @@ class XpmImageFile(ImageFile.ImageFile):
|
|||
format = "XPM"
|
||||
format_description = "X11 Pixel Map"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
if not _accept(self.fp.read(9)):
|
||||
msg = "not an XPM file"
|
||||
raise SyntaxError(msg)
|
||||
|
|
Loading…
Reference in New Issue
Block a user