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 further type hints #28

Merged
merged 1 commit into from
Dec 31, 2023
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions src/PIL/Image.py
Original file line number Diff line number Diff line change
Expand Up @@ -3191,7 +3191,7 @@ def _decompression_bomb_check(size):
)


def open(fp, mode="r", formats=None):
def open(fp, mode="r", formats=None) -> Image:
"""
Opens and identifies the given image file.
Expand Down Expand Up @@ -3416,7 +3416,7 @@ def merge(mode, bands):
# Plugin registry


def register_open(id, factory, accept=None):
def register_open(id, factory, accept=None) -> None:
"""
Register an image file plugin. This function should not be used
in application code.
Expand Down Expand Up @@ -3470,7 +3470,7 @@ def register_save_all(id, driver):
SAVE_ALL[id.upper()] = driver


def register_extension(id, extension):
def register_extension(id, extension) -> None:
"""
Registers an image extension. This function should not be
used in application code.
Expand Down
13 changes: 7 additions & 6 deletions src/PIL/IptcImagePlugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import os
import tempfile
from typing import Sequence

from . import Image, ImageFile
from ._binary import i16be as i16
Expand All @@ -27,7 +28,7 @@
COMPRESSION = {1: "raw", 5: "jpeg"}


def __getattr__(name):
def __getattr__(name: str) -> bytes:
if name == "PAD":
deprecate("IptcImagePlugin.PAD", 12)
return b"\0\0\0\0"
Expand All @@ -43,14 +44,14 @@ def _i8(c: int | bytes) -> int:
return c if isinstance(c, int) else c[0]


def i(c, *, _internal=False):
def i(c: bytes, *, _internal: bool = False) -> int:
""".. deprecated:: 10.2.0"""
if not _internal:
deprecate("IptcImagePlugin.i", 12)
return i32((b"\0\0\0\0" + c)[-4:])


def dump(c):
def dump(c: Sequence[int | bytes]) -> None:
""".. deprecated:: 10.2.0"""
deprecate("IptcImagePlugin.dump", 12)
for i in c:
Expand All @@ -67,10 +68,10 @@ class IptcImageFile(ImageFile.ImageFile):
format = "IPTC"
format_description = "IPTC/NAA"

def getint(self, key):
def getint(self, key: tuple[int, int]) -> int:
return i(self.info[key], _internal=True)

def field(self):
def field(self) -> tuple[tuple[int, int] | None, int]:
#
# get a IPTC field header
s = self.fp.read(5)
Expand Down Expand Up @@ -98,7 +99,7 @@ def field(self):

return tag, size

def _open(self):
def _open(self) -> None:
# load descriptive fields
while True:
offset = self.fp.tell()
Expand Down
Loading