Skip to content
Merged
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
47 changes: 47 additions & 0 deletions circuitpython_typing/pil.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney
#
# SPDX-License-Identifier: MIT

"""
`circuitpython_typing.pil`
================================================================================

Type annotation definitions for PIL Images.

* Author(s): Alec Delaney
"""

from typing import Tuple

# Protocol was introduced in Python 3.8.
try:
from typing import Protocol
except ImportError:
from typing_extensions import Protocol


class PixelAccess(Protocol):
"""Type annotation for PIL's PixelAccess class"""

# pylint: disable=invalid-name
def __getitem__(self, xy: Tuple[int, int]) -> int:
"""Get pixels by x, y coordinate"""
...


class Image(Protocol):
"""Type annotation for PIL's Image class"""

@property
def mode(self) -> str:
"""The mode of the image"""
...

@property
def size(self) -> Tuple[int, int]:
"""The size of the image"""
...

def load(self) -> PixelAccess:
"""Load the image for quick pixel access"""
...