Skip to content

Commit e5495c3

Browse files
authored
Merge pull request #49 from isacben/display-shapes-type-annotations
Added Type Annotations
2 parents 7a9759c + e0a85be commit e5495c3

File tree

7 files changed

+168
-52
lines changed

7 files changed

+168
-52
lines changed

adafruit_display_shapes/circle.py

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
2222
"""
2323

24+
try:
25+
from typing import Optional
26+
except ImportError:
27+
pass
28+
2429
from adafruit_display_shapes.roundrect import RoundRect
2530

2631
__version__ = "0.0.0-auto.0"
@@ -42,7 +47,16 @@ class Circle(RoundRect):
4247
4348
"""
4449

45-
def __init__(self, x0, y0, r, *, fill=None, outline=None, stroke=1):
50+
def __init__(
51+
self,
52+
x0: int,
53+
y0: int,
54+
r: int,
55+
*,
56+
fill: Optional[int] = None,
57+
outline: Optional[int] = None,
58+
stroke: int = 1,
59+
) -> None:
4660
super().__init__(
4761
x0 - r,
4862
y0 - r,
@@ -56,19 +70,19 @@ def __init__(self, x0, y0, r, *, fill=None, outline=None, stroke=1):
5670
self.r = r
5771

5872
@property
59-
def x0(self):
73+
def x0(self) -> int:
6074
"""The x-position of the center of the circle."""
6175
return self.x + self.r
6276

6377
@property
64-
def y0(self):
78+
def y0(self) -> int:
6579
"""The y-position of the center of the circle."""
6680
return self.y + self.r
6781

6882
@x0.setter
69-
def x0(self, x0):
83+
def x0(self, x0: int) -> None:
7084
self.x = x0 - self.r
7185

7286
@y0.setter
73-
def y0(self, y0):
87+
def y0(self, y0: int) -> None:
7488
self.y = y0 - self.r

adafruit_display_shapes/line.py

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
2222
"""
2323

24+
try:
25+
from typing import Optional
26+
except ImportError:
27+
pass
28+
2429
from adafruit_display_shapes.polygon import Polygon
2530

2631
__version__ = "0.0.0-auto.0"
@@ -38,15 +43,22 @@ class Line(Polygon):
3843
:param color: The color of the line.
3944
"""
4045

41-
def __init__(self, x0, y0, x1, y1, color):
46+
def __init__(
47+
self,
48+
x0: int,
49+
y0: int,
50+
x1: int,
51+
y1: int,
52+
color: int,
53+
) -> None:
4254
super().__init__([(x0, y0), (x1, y1)], outline=color)
4355

4456
@property
45-
def color(self):
57+
def color(self) -> Optional[int]:
4658
"""The line color value. Can be a hex value for a color or
4759
``None`` for no line color."""
4860
return self.outline
4961

5062
@color.setter
51-
def color(self, color):
63+
def color(self, color: Optional[int]) -> None:
5264
self.outline = color

adafruit_display_shapes/polygon.py

Lines changed: 21 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
2222
"""
2323

24+
try:
25+
from typing import Optional, List, Tuple
26+
except ImportError:
27+
pass
28+
2429
import displayio
2530

2631
__version__ = "0.0.0-auto.0"
@@ -36,7 +41,12 @@ class Polygon(displayio.TileGrid):
3641
``None`` for no outline.
3742
"""
3843

39-
def __init__(self, points, *, outline=None):
44+
def __init__(
45+
self,
46+
points: List[Tuple[int, int]],
47+
*,
48+
outline: Optional[int] = None,
49+
) -> None:
4050
xs = []
4151
ys = []
4252

@@ -77,7 +87,14 @@ def __init__(self, points, *, outline=None):
7787
)
7888

7989
# pylint: disable=invalid-name, too-many-locals, too-many-branches
80-
def _line(self, x0, y0, x1, y1, color):
90+
def _line(
91+
self,
92+
x0: int,
93+
y0: int,
94+
x1: int,
95+
y1: int,
96+
color: int,
97+
) -> None:
8198
if x0 == x1:
8299
if y0 > y1:
83100
y0, y1 = y1, y0
@@ -121,13 +138,13 @@ def _line(self, x0, y0, x1, y1, color):
121138
# pylint: enable=invalid-name, too-many-locals, too-many-branches
122139

123140
@property
124-
def outline(self):
141+
def outline(self) -> Optional[int]:
125142
"""The outline of the polygon. Can be a hex value for a color or
126143
``None`` for no outline."""
127144
return self._palette[1]
128145

129146
@outline.setter
130-
def outline(self, color):
147+
def outline(self, color: Optional[int]) -> None:
131148
if color is None:
132149
self._palette[1] = 0
133150
self._palette.make_transparent(1)

adafruit_display_shapes/rect.py

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@
2121
2222
"""
2323

24+
try:
25+
from typing import Optional
26+
except ImportError:
27+
pass
28+
2429
import displayio
2530

2631
__version__ = "0.0.0-auto.0"
@@ -43,7 +48,17 @@ class Rect(displayio.TileGrid):
4348
4449
"""
4550

46-
def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1):
51+
def __init__(
52+
self,
53+
x: int,
54+
y: int,
55+
width: int,
56+
height: int,
57+
*,
58+
fill: Optional[int] = None,
59+
outline: Optional[int] = None,
60+
stroke: int = 1,
61+
) -> None:
4762
self._bitmap = displayio.Bitmap(width, height, 2)
4863
self._palette = displayio.Palette(2)
4964

@@ -67,13 +82,13 @@ def __init__(self, x, y, width, height, *, fill=None, outline=None, stroke=1):
6782
super().__init__(self._bitmap, pixel_shader=self._palette, x=x, y=y)
6883

6984
@property
70-
def fill(self):
85+
def fill(self) -> Optional[int]:
7186
"""The fill of the rectangle. Can be a hex value for a color or ``None`` for
7287
transparent."""
7388
return self._palette[0]
7489

7590
@fill.setter
76-
def fill(self, color):
91+
def fill(self, color: Optional[int]) -> None:
7792
if color is None:
7893
self._palette[0] = 0
7994
self._palette.make_transparent(0)
@@ -82,13 +97,13 @@ def fill(self, color):
8297
self._palette.make_opaque(0)
8398

8499
@property
85-
def outline(self):
100+
def outline(self) -> Optional[int]:
86101
"""The outline of the rectangle. Can be a hex value for a color or ``None``
87102
for no outline."""
88103
return self._palette[1]
89104

90105
@outline.setter
91-
def outline(self, color):
106+
def outline(self, color: Optional[int]) -> None:
92107
if color is None:
93108
self._palette[1] = 0
94109
self._palette.make_transparent(1)

adafruit_display_shapes/roundrect.py

Lines changed: 31 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,11 @@
1111
1212
"""
1313

14+
try:
15+
from typing import Optional
16+
except ImportError:
17+
pass
18+
1419
import displayio
1520

1621
__version__ = "0.0.0-auto.0"
@@ -35,7 +40,18 @@ class RoundRect(displayio.TileGrid):
3540
3641
"""
3742

38-
def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1):
43+
def __init__(
44+
self,
45+
x: int,
46+
y: int,
47+
width: int,
48+
height: int,
49+
r: int,
50+
*,
51+
fill: Optional[int] = None,
52+
outline: Optional[int] = None,
53+
stroke: int = 1,
54+
) -> None:
3955
self._palette = displayio.Palette(3)
4056
self._palette.make_transparent(0)
4157
self._bitmap = displayio.Bitmap(width, height, 3)
@@ -85,17 +101,17 @@ def __init__(self, x, y, width, height, r, *, fill=None, outline=None, stroke=1)
85101
# pylint: disable=invalid-name, too-many-locals, too-many-branches
86102
def _helper(
87103
self,
88-
x0,
89-
y0,
90-
r,
104+
x0: int,
105+
y0: int,
106+
r: int,
91107
*,
92-
color,
93-
x_offset=0,
94-
y_offset=0,
95-
stroke=1,
96-
corner_flags=0xF,
97-
fill=False
98-
):
108+
color: int,
109+
x_offset: int = 0,
110+
y_offset: int = 0,
111+
stroke: int = 1,
112+
corner_flags: int = 0xF,
113+
fill: bool = False,
114+
) -> None:
99115
f = 1 - r
100116
ddF_x = 1
101117
ddF_y = -2 * r
@@ -142,13 +158,13 @@ def _helper(
142158
# pylint: enable=invalid-name, too-many-locals, too-many-branches
143159

144160
@property
145-
def fill(self):
161+
def fill(self) -> Optional[int]:
146162
"""The fill of the rounded-corner rectangle. Can be a hex value for a color or ``None`` for
147163
transparent."""
148164
return self._palette[2]
149165

150166
@fill.setter
151-
def fill(self, color):
167+
def fill(self, color: Optional[int]) -> None:
152168
if color is None:
153169
self._palette[2] = 0
154170
self._palette.make_transparent(2)
@@ -157,13 +173,13 @@ def fill(self, color):
157173
self._palette.make_opaque(2)
158174

159175
@property
160-
def outline(self):
176+
def outline(self) -> Optional[int]:
161177
"""The outline of the rounded-corner rectangle. Can be a hex value for a color or ``None``
162178
for no outline."""
163179
return self._palette[1]
164180

165181
@outline.setter
166-
def outline(self, color):
182+
def outline(self, color: Optional[int]) -> None:
167183
if color is None:
168184
self._palette[1] = 0
169185
self._palette.make_transparent(1)

0 commit comments

Comments
 (0)