Skip to content

Commit

Permalink
fix(typing): replace 3.10 union types with older-compatible Union t…
Browse files Browse the repository at this point in the history
…ypes

Fixes #17
  • Loading branch information
sworisbreathing committed Sep 15, 2024
1 parent eccee25 commit 9a39a3e
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 13 deletions.
22 changes: 11 additions & 11 deletions circuitpython_mocks/busio/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

from enum import Enum, auto
import sys
from typing import List, Optional
from typing import List, Optional, Union

import circuitpython_typing

Expand Down Expand Up @@ -189,8 +189,8 @@ def __new__(cls, clock: Pin, MOSI: Pin, MISO: Pin, **kwargs) -> "SPI":
def __init__(
self,
clock: Pin,
MOSI: Pin | None = None,
MISO: Pin | None = None,
MOSI: Union[Pin, None] = None,
MISO: Union[Pin, None] = None,
half_duplex: bool = False,
):
"""A class to mock :external:py:class:`busio.SPI`."""
Expand Down Expand Up @@ -297,16 +297,16 @@ class Parity(Enum):

def __init__(
self,
tx: Pin | None = None,
rx: Pin | None = None,
tx: Union[Pin, None] = None,
rx: Union[Pin, None] = None,
*,
rts: Pin | None = None,
cts: Pin | None = None,
rs485_dir: Pin | None = None,
rts: Union[Pin, None] = None,
cts: Union[Pin, None] = None,
rs485_dir: Union[Pin, None] = None,
rs485_invert: bool = False,
baudrate: int = 9600,
bits: int = 8,
parity: Parity | None = None,
parity: Union[Parity, None] = None,
stop: int = 1,
timeout: float = 1,
receiver_buffer_size: int = 64,
Expand All @@ -315,7 +315,7 @@ def __init__(
self._timeout = timeout
super().__init__()

def read(self, nbytes: int | None = None) -> Optional[bytes]:
def read(self, nbytes: Union[int, None] = None) -> Optional[bytes]:
"""A function that mocks :external:py:meth:`busio.UART.read()`.
.. mock-expects::
Expand Down Expand Up @@ -362,7 +362,7 @@ def readline(self) -> Optional[bytes]:
op.assert_response(buf, 0, len_buf)
return None if buf else bytes(buf)

def write(self, buf: circuitpython_typing.ReadableBuffer) -> int | None:
def write(self, buf: circuitpython_typing.ReadableBuffer) -> Union[int, None]:
"""A function that mocks :external:py:meth:`busio.UART.write()`.
.. mock-expects::
Expand Down
7 changes: 5 additions & 2 deletions circuitpython_mocks/digitalio/operations.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
from typing import Union


class _State:
def __init__(self, state: bool | int) -> None:
def __init__(self, state: Union[bool, int]) -> None:
self.state = bool(state)

def assert_state(self, value: bool | int):
def assert_state(self, value: Union[bool, int]):
assert self.state is bool(
value
), "Expected pin state does not match given pin state"
Expand Down

0 comments on commit 9a39a3e

Please sign in to comment.