Skip to content

Commit

Permalink
Merge pull request #7719 from radarhere/type_hints_msp
Browse files Browse the repository at this point in the history
Added type hints to MspImagePlugin
  • Loading branch information
mergify[bot] authored Jan 15, 2024
2 parents fd5df78 + edaf7ac commit ab1de6d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion src/PIL/ImageFile.py
Original file line number Diff line number Diff line change
Expand Up @@ -713,7 +713,7 @@ def decode(self, buffer):
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
Expand Down
12 changes: 8 additions & 4 deletions src/PIL/MspImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
# read MSP files


def _accept(prefix):
def _accept(prefix: bytes) -> bool:
return prefix[:4] in [b"DanM", b"LinS"]


Expand All @@ -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"
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -159,7 +163,7 @@ def decode(self, buffer):
# 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)
Expand Down

0 comments on commit ab1de6d

Please sign in to comment.