Skip to content

Commit 20f292d

Browse files
authored
Merge pull request #77 from tekktrik/dev/typing-fix
Fix Unions to Literals
2 parents ab46a73 + dc8b641 commit 20f292d

11 files changed

+33
-22
lines changed

adafruit_epd/epd.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
try:
1919
"""Needed for type annotations"""
2020
from typing import Any, Union, Callable, Optional
21+
from typing_extensions import Literal
2122
from busio import SPI
2223
from digitalio import DigitalInOut
2324
from circuitpython_typing.pil import Image
@@ -247,7 +248,7 @@ def set_ram_address(self, x: int, y: int) -> None:
247248
"""Set the RAM address location, must be implemented in subclass"""
248249
raise NotImplementedError()
249250

250-
def set_black_buffer(self, index: Union[0, 1], inverted: bool) -> None:
251+
def set_black_buffer(self, index: Literal[0, 1], inverted: bool) -> None:
251252
"""Set the index for the black buffer data (0 or 1) and whether its inverted"""
252253
if index == 0:
253254
self._blackframebuf = self._framebuf1
@@ -257,7 +258,7 @@ def set_black_buffer(self, index: Union[0, 1], inverted: bool) -> None:
257258
raise RuntimeError("Buffer index must be 0 or 1")
258259
self._black_inverted = inverted
259260

260-
def set_color_buffer(self, index: Union[0, 1], inverted: bool) -> None:
261+
def set_color_buffer(self, index: Literal[0, 1], inverted: bool) -> None:
261262
"""Set the index for the color buffer data (0 or 1) and whether its inverted"""
262263
if index == 0:
263264
self._colorframebuf = self._framebuf1
@@ -271,7 +272,7 @@ def _color_dup(
271272
self,
272273
func: Callable,
273274
args: Any,
274-
color: Union[0, 1, 2, 3, 4, 5],
275+
color: Literal[0, 1, 2, 3, 4, 5],
275276
) -> None:
276277
black = getattr(self._blackframebuf, func)
277278
red = getattr(self._colorframebuf, func)
@@ -368,7 +369,7 @@ def height(self) -> int:
368369
return self._width
369370

370371
@property
371-
def rotation(self) -> Union[0, 1, 2, 3]:
372+
def rotation(self) -> Literal[0, 1, 2, 3]:
372373
"""The rotation of the display, can be one of (0, 1, 2, 3)"""
373374
return self._framebuf1.rotation
374375

adafruit_epd/il0373.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"""Needed for type annotations"""
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -144,7 +145,7 @@ def update(self) -> None:
144145
if not self._busy:
145146
time.sleep(15) # wait 15 seconds
146147

147-
def write_ram(self, index: Union[0, 1]) -> int:
148+
def write_ram(self, index: Literal[0, 1]) -> int:
148149
"""Send the one byte command for starting the RAM write process. Returns
149150
the byte read at the same time over SPI. index is the RAM buffer, can be
150151
0 or 1 for tri-color displays."""

adafruit_epd/il0398.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"""Needed for type annotations"""
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -144,7 +145,7 @@ def update(self) -> None:
144145
if not self._busy:
145146
time.sleep(15) # wait 15 seconds
146147

147-
def write_ram(self, index: Union[0, 1]) -> int:
148+
def write_ram(self, index: Literal[0, 1]) -> int:
148149
"""Send the one byte command for starting the RAM write process. Returns
149150
the byte read at the same time over SPI. index is the RAM buffer, can be
150151
0 or 1 for tri-color displays."""

adafruit_epd/il91874.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"Needed for type annotations"
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -167,7 +168,7 @@ def update(self) -> None:
167168
if not self._busy:
168169
time.sleep(16) # wait 16 seconds
169170

170-
def write_ram(self, index: Union[0, 1]) -> int:
171+
def write_ram(self, index: Literal[0, 1]) -> int:
171172
"""Send the one byte command for starting the RAM write process. Returns
172173
the byte read at the same time over SPI. index is the RAM buffer, can be
173174
0 or 1 for tri-color displays."""

adafruit_epd/ssd1608.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"""Needed for type annotations"""
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -156,7 +157,7 @@ def update(self) -> None:
156157
if not self._busy:
157158
time.sleep(3) # wait 3 seconds
158159

159-
def write_ram(self, index: Union[0]) -> int:
160+
def write_ram(self, index: Literal[0]) -> int:
160161
"""Send the one byte command for starting the RAM write process. Returns
161162
the byte read at the same time over SPI. index is the RAM buffer, can be
162163
0 or 1 for tri-color displays."""

adafruit_epd/ssd1675.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"""Needed for type annotations"""
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -178,7 +179,7 @@ def update(self) -> None:
178179
if not self._busy:
179180
time.sleep(3) # wait 3 seconds
180181

181-
def write_ram(self, index: Union[0, 1]) -> int:
182+
def write_ram(self, index: Literal[0, 1]) -> int:
182183
"""Send the one byte command for starting the RAM write process. Returns
183184
the byte read at the same time over SPI. index is the RAM buffer, can be
184185
0 or 1 for tri-color displays."""

adafruit_epd/ssd1675b.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"""Needed for type annotations"""
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -220,7 +221,7 @@ def update(self) -> None:
220221
if not self._busy:
221222
time.sleep(3) # wait 3 seconds
222223

223-
def write_ram(self, index: Union[0, 1]) -> int:
224+
def write_ram(self, index: Literal[0, 1]) -> int:
224225
"""Send the one byte command for starting the RAM write process. Returns
225226
the byte read at the same time over SPI. index is the RAM buffer, can be
226227
0 or 1 for tri-color displays."""

adafruit_epd/ssd1680.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"""Needed for type annotations"""
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -191,7 +192,7 @@ def update(self) -> None:
191192
if not self._busy:
192193
time.sleep(3) # wait 3 seconds
193194

194-
def write_ram(self, index: Union[0, 1]) -> int:
195+
def write_ram(self, index: Literal[0, 1]) -> int:
195196
"""Send the one byte command for starting the RAM write process. Returns
196197
the byte read at the same time over SPI. index is the RAM buffer, can be
197198
0 or 1 for tri-color displays."""

adafruit_epd/ssd1681.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
from adafruit_epd.epd import Adafruit_EPD
1616

1717
try:
18-
from typing import Union
18+
import typing # pylint: disable=unused-import
19+
from typing_extensions import Literal
1920
from busio import SPI
2021
from digitalio import DigitalInOut
2122

@@ -173,7 +174,7 @@ def update(self) -> None:
173174
if not self._busy:
174175
time.sleep(3) # wait 3 seconds
175176

176-
def write_ram(self, index: Union[0, 1]) -> int:
177+
def write_ram(self, index: Literal[0, 1]) -> int:
177178
"""Send the one byte command for starting the RAM write process. Returns
178179
the byte read at the same time over SPI. index is the RAM buffer, can be
179180
0 or 1 for tri-color displays."""

adafruit_epd/uc8151d.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,8 @@
1616

1717
try:
1818
"""Needed for type annotations"""
19-
from typing import Union
19+
import typing # pylint: disable=unused-import
20+
from typing_extensions import Literal
2021
from busio import SPI
2122
from digitalio import DigitalInOut
2223

@@ -152,7 +153,7 @@ def update(self) -> None:
152153
if not self._busy:
153154
time.sleep(15) # wait 15 seconds
154155

155-
def write_ram(self, index: Union[0, 1]) -> int:
156+
def write_ram(self, index: Literal[0, 1]) -> int:
156157
"""Send the one byte command for starting the RAM write process. Returns
157158
the byte read at the same time over SPI. index is the RAM buffer, can be
158159
0 or 1 for tri-color displays."""

requirements.txt

+1
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,4 @@
55
Adafruit-Blinka
66
adafruit-circuitpython-busdevice
77
adafruit-circuitpython-framebuf
8+
typing-extensions~=4.0

0 commit comments

Comments
 (0)