Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix compatibility with older Python versions #18

Merged
merged 3 commits into from
Sep 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion circuitpython_mocks/_mixins.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
from collections import deque
from typing import Self, Deque, Union, TYPE_CHECKING
from typing import Deque, Union, TYPE_CHECKING

try:
from typing import Self
except ImportError: # pragma: no cover
from typing_extensions import Self


if TYPE_CHECKING:
from circuitpython_mocks.busio.operations import (
Expand Down
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
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
adafruit-circuitpython-typing
pytest
typing-extensions~=4.0