Skip to content

Commit 33d26e8

Browse files
authored
Merge pull request #13 from tekktrik/doc/add-image-protocol
Add PIL.Image protocol
2 parents 883409a + 706cade commit 33d26e8

File tree

1 file changed

+47
-0
lines changed

1 file changed

+47
-0
lines changed

circuitpython_typing/pil.py

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Alec Delaney
2+
#
3+
# SPDX-License-Identifier: MIT
4+
5+
"""
6+
`circuitpython_typing.pil`
7+
================================================================================
8+
9+
Type annotation definitions for PIL Images.
10+
11+
* Author(s): Alec Delaney
12+
"""
13+
14+
from typing import Tuple
15+
16+
# Protocol was introduced in Python 3.8.
17+
try:
18+
from typing import Protocol
19+
except ImportError:
20+
from typing_extensions import Protocol
21+
22+
23+
class PixelAccess(Protocol):
24+
"""Type annotation for PIL's PixelAccess class"""
25+
26+
# pylint: disable=invalid-name
27+
def __getitem__(self, xy: Tuple[int, int]) -> int:
28+
"""Get pixels by x, y coordinate"""
29+
...
30+
31+
32+
class Image(Protocol):
33+
"""Type annotation for PIL's Image class"""
34+
35+
@property
36+
def mode(self) -> str:
37+
"""The mode of the image"""
38+
...
39+
40+
@property
41+
def size(self) -> Tuple[int, int]:
42+
"""The size of the image"""
43+
...
44+
45+
def load(self) -> PixelAccess:
46+
"""Load the image for quick pixel access"""
47+
...

0 commit comments

Comments
 (0)