Skip to content

Commit f17c376

Browse files
authored
remove support for Python 3.9 (#1996)
Co-authored-by: zariiii9003 <[email protected]>
1 parent 4ac05e5 commit f17c376

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+363
-456
lines changed

.github/dependabot.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,12 @@
55

66
version: 2
77
updates:
8-
- package-ecosystem: "uv"
8+
- package-ecosystem: "pip"
99
# Enable version updates for development dependencies
1010
directory: "/"
1111
schedule:
1212
interval: "monthly"
13+
versioning-strategy: "increase-if-necessary"
1314
groups:
1415
dev-deps:
1516
patterns:
@@ -23,4 +24,4 @@ updates:
2324
groups:
2425
github-actions:
2526
patterns:
26-
- "*"
27+
- "*"

.github/workflows/ci.yml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ jobs:
2121
matrix:
2222
os: [ubuntu-latest, macos-latest, windows-latest]
2323
env: [
24-
"py39",
2524
"py310",
2625
"py311",
2726
"py312",

README.rst

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Library Version Python
6161
4.0+ 3.7+
6262
4.3+ 3.8+
6363
4.6+ 3.9+
64+
main branch 3.10+
6465
============================== ===========
6566

6667

can/_entry_points.py

Lines changed: 4 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import importlib
2-
import sys
32
from dataclasses import dataclass
43
from importlib.metadata import entry_points
54
from typing import Any
@@ -16,19 +15,7 @@ def load(self) -> Any:
1615
return getattr(module, self.class_name)
1716

1817

19-
# See https://docs.python.org/3/library/importlib.metadata.html#entry-points,
20-
# "Compatibility Note".
21-
if sys.version_info >= (3, 10):
22-
23-
def read_entry_points(group: str) -> list[_EntryPoint]:
24-
return [
25-
_EntryPoint(ep.name, ep.module, ep.attr) for ep in entry_points(group=group)
26-
]
27-
28-
else:
29-
30-
def read_entry_points(group: str) -> list[_EntryPoint]:
31-
return [
32-
_EntryPoint(ep.name, *ep.value.split(":", maxsplit=1))
33-
for ep in entry_points().get(group, []) # pylint: disable=no-member
34-
]
18+
def read_entry_points(group: str) -> list[_EntryPoint]:
19+
return [
20+
_EntryPoint(ep.name, ep.module, ep.attr) for ep in entry_points(group=group)
21+
]

can/broadcastmanager.py

Lines changed: 16 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,10 @@
1212
import threading
1313
import time
1414
import warnings
15-
from collections.abc import Sequence
15+
from collections.abc import Callable, Sequence
1616
from typing import (
1717
TYPE_CHECKING,
18-
Callable,
1918
Final,
20-
Optional,
21-
Union,
2219
cast,
2320
)
2421

@@ -78,7 +75,7 @@ def wait_inf(self, event: _Pywin32Event) -> None:
7875
)
7976

8077

81-
PYWIN32: Optional[_Pywin32] = None
78+
PYWIN32: _Pywin32 | None = None
8279
if sys.platform == "win32" and sys.version_info < (3, 11):
8380
try:
8481
PYWIN32 = _Pywin32()
@@ -105,9 +102,7 @@ class CyclicSendTaskABC(CyclicTask, abc.ABC):
105102
Message send task with defined period
106103
"""
107104

108-
def __init__(
109-
self, messages: Union[Sequence[Message], Message], period: float
110-
) -> None:
105+
def __init__(self, messages: Sequence[Message] | Message, period: float) -> None:
111106
"""
112107
:param messages:
113108
The messages to be sent periodically.
@@ -125,7 +120,7 @@ def __init__(
125120

126121
@staticmethod
127122
def _check_and_convert_messages(
128-
messages: Union[Sequence[Message], Message],
123+
messages: Sequence[Message] | Message,
129124
) -> tuple[Message, ...]:
130125
"""Helper function to convert a Message or Sequence of messages into a
131126
tuple, and raises an error when the given value is invalid.
@@ -164,9 +159,9 @@ def _check_and_convert_messages(
164159
class LimitedDurationCyclicSendTaskABC(CyclicSendTaskABC, abc.ABC):
165160
def __init__(
166161
self,
167-
messages: Union[Sequence[Message], Message],
162+
messages: Sequence[Message] | Message,
168163
period: float,
169-
duration: Optional[float],
164+
duration: float | None,
170165
) -> None:
171166
"""Message send task with a defined duration and period.
172167
@@ -181,7 +176,7 @@ def __init__(
181176
"""
182177
super().__init__(messages, period)
183178
self.duration = duration
184-
self.end_time: Optional[float] = None
179+
self.end_time: float | None = None
185180

186181

187182
class RestartableCyclicTaskABC(CyclicSendTaskABC, abc.ABC):
@@ -215,7 +210,7 @@ def _check_modified_messages(self, messages: tuple[Message, ...]) -> None:
215210
"from when the task was created"
216211
)
217212

218-
def modify_data(self, messages: Union[Sequence[Message], Message]) -> None:
213+
def modify_data(self, messages: Sequence[Message] | Message) -> None:
219214
"""Update the contents of the periodically sent messages, without
220215
altering the timing.
221216
@@ -242,7 +237,7 @@ class MultiRateCyclicSendTaskABC(CyclicSendTaskABC, abc.ABC):
242237
def __init__(
243238
self,
244239
channel: typechecking.Channel,
245-
messages: Union[Sequence[Message], Message],
240+
messages: Sequence[Message] | Message,
246241
count: int, # pylint: disable=unused-argument
247242
initial_period: float, # pylint: disable=unused-argument
248243
subsequent_period: float,
@@ -272,12 +267,12 @@ def __init__(
272267
self,
273268
bus: "BusABC",
274269
lock: threading.Lock,
275-
messages: Union[Sequence[Message], Message],
270+
messages: Sequence[Message] | Message,
276271
period: float,
277-
duration: Optional[float] = None,
278-
on_error: Optional[Callable[[Exception], bool]] = None,
272+
duration: float | None = None,
273+
on_error: Callable[[Exception], bool] | None = None,
279274
autostart: bool = True,
280-
modifier_callback: Optional[Callable[[Message], None]] = None,
275+
modifier_callback: Callable[[Message], None] | None = None,
281276
) -> None:
282277
"""Transmits `messages` with a `period` seconds for `duration` seconds on a `bus`.
283278
@@ -298,13 +293,13 @@ def __init__(
298293
self.bus = bus
299294
self.send_lock = lock
300295
self.stopped = True
301-
self.thread: Optional[threading.Thread] = None
296+
self.thread: threading.Thread | None = None
302297
self.on_error = on_error
303298
self.modifier_callback = modifier_callback
304299

305300
self.period_ms = int(round(period * 1000, 0))
306301

307-
self.event: Optional[_Pywin32Event] = None
302+
self.event: _Pywin32Event | None = None
308303
if PYWIN32:
309304
if self.period_ms == 0:
310305
# A period of 0 would mean that the timer is signaled only once
@@ -338,7 +333,7 @@ def start(self) -> None:
338333
self.thread = threading.Thread(target=self._run, name=name)
339334
self.thread.daemon = True
340335

341-
self.end_time: Optional[float] = (
336+
self.end_time: float | None = (
342337
time.perf_counter() + self.duration if self.duration else None
343338
)
344339

can/bus.py

Lines changed: 18 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,11 @@
66
import logging
77
import threading
88
from abc import ABC, abstractmethod
9-
from collections.abc import Iterator, Sequence
9+
from collections.abc import Callable, Iterator, Sequence
1010
from enum import Enum, auto
1111
from time import time
1212
from types import TracebackType
1313
from typing import (
14-
Callable,
15-
Optional,
16-
Union,
1714
cast,
1815
)
1916

@@ -68,7 +65,7 @@ class BusABC(ABC):
6865
def __init__(
6966
self,
7067
channel: can.typechecking.Channel,
71-
can_filters: Optional[can.typechecking.CanFilters] = None,
68+
can_filters: can.typechecking.CanFilters | None = None,
7269
**kwargs: object,
7370
):
7471
"""Construct and open a CAN bus instance of the specified type.
@@ -101,7 +98,7 @@ def __init__(
10198
def __str__(self) -> str:
10299
return self.channel_info
103100

104-
def recv(self, timeout: Optional[float] = None) -> Optional[Message]:
101+
def recv(self, timeout: float | None = None) -> Message | None:
105102
"""Block waiting for a message from the Bus.
106103
107104
:param timeout:
@@ -139,9 +136,7 @@ def recv(self, timeout: Optional[float] = None) -> Optional[Message]:
139136

140137
return None
141138

142-
def _recv_internal(
143-
self, timeout: Optional[float]
144-
) -> tuple[Optional[Message], bool]:
139+
def _recv_internal(self, timeout: float | None) -> tuple[Message | None, bool]:
145140
"""
146141
Read a message from the bus and tell whether it was filtered.
147142
This methods may be called by :meth:`~can.BusABC.recv`
@@ -184,7 +179,7 @@ def _recv_internal(
184179
raise NotImplementedError("Trying to read from a write only bus?")
185180

186181
@abstractmethod
187-
def send(self, msg: Message, timeout: Optional[float] = None) -> None:
182+
def send(self, msg: Message, timeout: float | None = None) -> None:
188183
"""Transmit a message to the CAN bus.
189184
190185
Override this method to enable the transmit path.
@@ -205,12 +200,12 @@ def send(self, msg: Message, timeout: Optional[float] = None) -> None:
205200

206201
def send_periodic(
207202
self,
208-
msgs: Union[Message, Sequence[Message]],
203+
msgs: Message | Sequence[Message],
209204
period: float,
210-
duration: Optional[float] = None,
205+
duration: float | None = None,
211206
store_task: bool = True,
212207
autostart: bool = True,
213-
modifier_callback: Optional[Callable[[Message], None]] = None,
208+
modifier_callback: Callable[[Message], None] | None = None,
214209
) -> can.broadcastmanager.CyclicSendTaskABC:
215210
"""Start sending messages at a given period on this bus.
216211
@@ -297,11 +292,11 @@ def wrapped_stop_method(remove_task: bool = True) -> None:
297292

298293
def _send_periodic_internal(
299294
self,
300-
msgs: Union[Sequence[Message], Message],
295+
msgs: Sequence[Message] | Message,
301296
period: float,
302-
duration: Optional[float] = None,
297+
duration: float | None = None,
303298
autostart: bool = True,
304-
modifier_callback: Optional[Callable[[Message], None]] = None,
299+
modifier_callback: Callable[[Message], None] | None = None,
305300
) -> can.broadcastmanager.CyclicSendTaskABC:
306301
"""Default implementation of periodic message sending using threading.
307302
@@ -378,20 +373,18 @@ def __iter__(self) -> Iterator[Message]:
378373
yield msg
379374

380375
@property
381-
def filters(self) -> Optional[can.typechecking.CanFilters]:
376+
def filters(self) -> can.typechecking.CanFilters | None:
382377
"""
383378
Modify the filters of this bus. See :meth:`~can.BusABC.set_filters`
384379
for details.
385380
"""
386381
return self._filters
387382

388383
@filters.setter
389-
def filters(self, filters: Optional[can.typechecking.CanFilters]) -> None:
384+
def filters(self, filters: can.typechecking.CanFilters | None) -> None:
390385
self.set_filters(filters)
391386

392-
def set_filters(
393-
self, filters: Optional[can.typechecking.CanFilters] = None
394-
) -> None:
387+
def set_filters(self, filters: can.typechecking.CanFilters | None = None) -> None:
395388
"""Apply filtering to all messages received by this Bus.
396389
397390
All messages that match at least one filter are returned.
@@ -417,7 +410,7 @@ def set_filters(
417410
with contextlib.suppress(NotImplementedError):
418411
self._apply_filters(self._filters)
419412

420-
def _apply_filters(self, filters: Optional[can.typechecking.CanFilters]) -> None:
413+
def _apply_filters(self, filters: can.typechecking.CanFilters | None) -> None:
421414
"""
422415
Hook for applying the filters to the underlying kernel or
423416
hardware if supported/implemented by the interface.
@@ -484,9 +477,9 @@ def __enter__(self) -> Self:
484477

485478
def __exit__(
486479
self,
487-
exc_type: Optional[type[BaseException]],
488-
exc_value: Optional[BaseException],
489-
traceback: Optional[TracebackType],
480+
exc_type: type[BaseException] | None,
481+
exc_value: BaseException | None,
482+
traceback: TracebackType | None,
490483
) -> None:
491484
self.shutdown()
492485

0 commit comments

Comments
 (0)