mirror of
https://github.com/python-pillow/Pillow.git
synced 2024-12-25 17:36:18 +03:00
Added type hints
This commit is contained in:
parent
fd5df78669
commit
6a2bdb6feb
|
@ -3507,7 +3507,7 @@ def registered_extensions():
|
|||
return EXTENSION
|
||||
|
||||
|
||||
def register_decoder(name, decoder):
|
||||
def register_decoder(name: str, decoder) -> None:
|
||||
"""
|
||||
Registers an image decoder. This function should not be
|
||||
used in application code.
|
||||
|
|
|
@ -713,7 +713,7 @@ class PyDecoder(PyCodec):
|
|||
msg = "unavailable in base decoder"
|
||||
raise NotImplementedError(msg)
|
||||
|
||||
def set_as_raw(self, data, rawmode=None):
|
||||
def set_as_raw(self, data: bytes, rawmode = None) -> None:
|
||||
"""
|
||||
Convenience method to set the internal image from a stream of raw data
|
||||
|
||||
|
|
|
@ -35,7 +35,7 @@ from ._binary import o16le as o16
|
|||
# read MSP files
|
||||
|
||||
|
||||
def _accept(prefix):
|
||||
def _accept(prefix: bytes) -> bool:
|
||||
return prefix[:4] in [b"DanM", b"LinS"]
|
||||
|
||||
|
||||
|
@ -48,8 +48,10 @@ class MspImageFile(ImageFile.ImageFile):
|
|||
format = "MSP"
|
||||
format_description = "Windows Paint"
|
||||
|
||||
def _open(self):
|
||||
def _open(self) -> None:
|
||||
# Header
|
||||
assert self.fp is not None
|
||||
|
||||
s = self.fp.read(32)
|
||||
if not _accept(s):
|
||||
msg = "not an MSP file"
|
||||
|
@ -109,7 +111,9 @@ class MspDecoder(ImageFile.PyDecoder):
|
|||
|
||||
_pulls_fd = True
|
||||
|
||||
def decode(self, buffer):
|
||||
def decode(self, buffer: bytes) -> tuple[int, int]:
|
||||
assert self.fd is not None
|
||||
|
||||
img = io.BytesIO()
|
||||
blank_line = bytearray((0xFF,) * ((self.state.xsize + 7) // 8))
|
||||
try:
|
||||
|
@ -159,7 +163,7 @@ Image.register_decoder("MSP", MspDecoder)
|
|||
# write MSP files (uncompressed only)
|
||||
|
||||
|
||||
def _save(im, fp, filename):
|
||||
def _save(im: Image.Image, fp: io.BytesIO, filename: str) -> None:
|
||||
if im.mode != "1":
|
||||
msg = f"cannot write mode {im.mode} as MSP"
|
||||
raise OSError(msg)
|
||||
|
|
Loading…
Reference in New Issue
Block a user