Skip to content

Commit 9905a43

Browse files
committed
Removed python 3.9 support
1 parent f134cde commit 9905a43

3 files changed

Lines changed: 23 additions & 27 deletions

File tree

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ jobs:
2828
strategy:
2929
fail-fast: false
3030
matrix:
31-
python-version: ["3.9","3.10","3.11","3.12","3.13"]
31+
python-version: ["3.10","3.11","3.12","3.13"]
3232

3333
name: Test on Python ${{ matrix.python-version }}
3434
steps:

can_waveshare/bus.py

Lines changed: 21 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,17 @@
1414

1515
_WS_WIRE_LEN = 13 # fixed length of Waveshare TCP CAN frame
1616

17-
class _WSFrameMethods:
17+
18+
@dataclass(slots=True)
19+
class _WSFrame:
20+
"""Waveshare fixed 13-byte TCP wire frame (Py3.10+ with dataclass slots)."""
21+
22+
can_id: int
23+
data: bytes
24+
extended: bool
25+
rtr: bool
26+
dlc: int
27+
1828
@staticmethod
1929
def from_bytes(buf: bytes) -> "_WSFrame":
2030
"""Decode a 13-byte buffer into a _WSFrame."""
@@ -27,7 +37,7 @@ def from_bytes(buf: bytes) -> "_WSFrame":
2737
if dlc > 8:
2838
raise ValueError(f"Invalid DLC {dlc}")
2939
can_id = int.from_bytes(buf[1:5], "big", signed=False)
30-
data = bytes(buf[5:5 + dlc])
40+
data = bytes(buf[5 : 5 + dlc])
3141
return _WSFrame(can_id=can_id, data=data, extended=extended, rtr=rtr, dlc=dlc)
3242

3343
def to_bytes(self) -> bytes:
@@ -41,34 +51,18 @@ def to_bytes(self) -> bytes:
4151
else:
4252
if self.dlc != len(self.data):
4353
raise ValueError("dlc must equal len(data) for data frames")
44-
b0 = (0x80 if self.extended else 0) | (0x40 if self.rtr else 0) | (self.dlc & 0x0F)
54+
b0 = (
55+
(0x80 if self.extended else 0)
56+
| (0x40 if self.rtr else 0)
57+
| (self.dlc & 0x0F)
58+
)
4559
out = bytearray(_WS_WIRE_LEN)
4660
out[0] = b0
4761
out[1:5] = int(self.can_id).to_bytes(4, "big", signed=False)
4862
if not self.rtr and self.dlc:
49-
out[5:5 + self.dlc] = self.data
63+
out[5 : 5 + self.dlc] = self.data
5064
return bytes(out)
5165

52-
if sys.version_info >= (3, 10):
53-
@dataclass(slots=True)
54-
class _WSFrame(_WSFrameMethods):
55-
"""Waveshare fixed 13-byte TCP wire frame (Py3.10+ with dataclass slots)."""
56-
can_id: int
57-
data: bytes
58-
extended: bool
59-
rtr: bool
60-
dlc: int
61-
else:
62-
@dataclass
63-
class _WSFrame(_WSFrameMethods):
64-
"""Waveshare fixed 13-byte TCP wire frame (Py3.9 with manual __slots__)."""
65-
__slots__ = ("can_id", "data", "extended", "rtr", "dlc")
66-
can_id: int
67-
data: bytes
68-
extended: bool
69-
rtr: bool
70-
dlc: int
71-
7266

7367
def _matches_filter(msg: can.Message, flt: dict[str, Any]) -> bool:
7468
"""
@@ -268,7 +262,9 @@ def send(self, msg: can.Message, timeout: Optional[float] = None) -> None:
268262
try:
269263
_send_all(self._sock, payload)
270264
except OSError as e:
271-
raise can.CanError(f"WaveShareBus.send failed (id=0x{arb_id:X}): {e}") from e
265+
raise can.CanError(
266+
f"WaveShareBus.send failed (id=0x{arb_id:X}): {e}"
267+
) from e
272268

273269
# record for own-echo suppression (if active)
274270
if self._suppress_own:

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ name = "can-waveshare"
77
dynamic = ["version"]
88
description = "python-can backend for Waveshare 2-CH-CAN-TO-ETH (13-byte TCP wire format over TCP)"
99
readme = "README.md"
10-
requires-python = ">=3.9"
10+
requires-python = ">=3.10"
1111
license = { text = "Apache-2.0" }
1212
authors = [{ name = "Klaudiusz Staniek" }]
1313
dependencies = ["python-can>=4.2"]

0 commit comments

Comments
 (0)