Skip to content

Commit

Permalink
Merge pull request #77 from tekktrik/dev/typing-fix
Browse files Browse the repository at this point in the history
Fix Unions to Literals
  • Loading branch information
FoamyGuy authored Jun 7, 2023
2 parents ab46a73 + dc8b641 commit 20f292d
Show file tree
Hide file tree
Showing 11 changed files with 33 additions and 22 deletions.
9 changes: 5 additions & 4 deletions adafruit_epd/epd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
try:
"""Needed for type annotations"""
from typing import Any, Union, Callable, Optional
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut
from circuitpython_typing.pil import Image
Expand Down Expand Up @@ -247,7 +248,7 @@ def set_ram_address(self, x: int, y: int) -> None:
"""Set the RAM address location, must be implemented in subclass"""
raise NotImplementedError()

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

def set_color_buffer(self, index: Union[0, 1], inverted: bool) -> None:
def set_color_buffer(self, index: Literal[0, 1], inverted: bool) -> None:
"""Set the index for the color buffer data (0 or 1) and whether its inverted"""
if index == 0:
self._colorframebuf = self._framebuf1
Expand All @@ -271,7 +272,7 @@ def _color_dup(
self,
func: Callable,
args: Any,
color: Union[0, 1, 2, 3, 4, 5],
color: Literal[0, 1, 2, 3, 4, 5],
) -> None:
black = getattr(self._blackframebuf, func)
red = getattr(self._colorframebuf, func)
Expand Down Expand Up @@ -368,7 +369,7 @@ def height(self) -> int:
return self._width

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

Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/il0373.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"""Needed for type annotations"""
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/il0398.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"""Needed for type annotations"""
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/il91874.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"Needed for type annotations"
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/ssd1608.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"""Needed for type annotations"""
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0]) -> int:
def write_ram(self, index: Literal[0]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/ssd1675.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"""Needed for type annotations"""
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/ssd1675b.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"""Needed for type annotations"""
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/ssd1680.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"""Needed for type annotations"""
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/ssd1681.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@
from adafruit_epd.epd import Adafruit_EPD

try:
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
5 changes: 3 additions & 2 deletions adafruit_epd/uc8151d.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@

try:
"""Needed for type annotations"""
from typing import Union
import typing # pylint: disable=unused-import
from typing_extensions import Literal
from busio import SPI
from digitalio import DigitalInOut

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

def write_ram(self, index: Union[0, 1]) -> int:
def write_ram(self, index: Literal[0, 1]) -> int:
"""Send the one byte command for starting the RAM write process. Returns
the byte read at the same time over SPI. index is the RAM buffer, can be
0 or 1 for tri-color displays."""
Expand Down
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@
Adafruit-Blinka
adafruit-circuitpython-busdevice
adafruit-circuitpython-framebuf
typing-extensions~=4.0

0 comments on commit 20f292d

Please sign in to comment.