Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added type hints to MspImagePlugin #7719

Merged
merged 2 commits into from Jan 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/PIL/Image.py
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
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
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