Skip to content

Commit c46d3ea

Browse files
authored
Raise minimum python version to 3.9 (#1931)
* require python>=3.9 * fix formatting * pin ruff==0.11.12, mypy==1.16.* --------- Co-authored-by: zariiii9003 <[email protected]>
1 parent 5d62394 commit c46d3ea

Some content is hidden

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

51 files changed

+209
-236
lines changed

.github/workflows/ci.yml

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ jobs:
1818
os: [ubuntu-latest, macos-latest, windows-latest]
1919
experimental: [false]
2020
python-version: [
21-
"3.8",
2221
"3.9",
2322
"3.10",
2423
"3.11",
@@ -81,9 +80,6 @@ jobs:
8180
run: |
8281
python -m pip install --upgrade pip
8382
pip install -e .[lint]
84-
- name: mypy 3.8
85-
run: |
86-
mypy --python-version 3.8 .
8783
- name: mypy 3.9
8884
run: |
8985
mypy --python-version 3.9 .

README.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ python-can
33

44
|pypi| |conda| |python_implementation| |downloads| |downloads_monthly|
55

6-
|docs| |github-actions| |coverage| |mergify| |formatter|
6+
|docs| |github-actions| |coverage| |formatter|
77

88
.. |pypi| image:: https://img.shields.io/pypi/v/python-can.svg
99
:target: https://pypi.python.org/pypi/python-can/
@@ -41,10 +41,6 @@ python-can
4141
:target: https://coveralls.io/github/hardbyte/python-can?branch=develop
4242
:alt: Test coverage reports on Coveralls.io
4343

44-
.. |mergify| image:: https://img.shields.io/endpoint.svg?url=https://api.mergify.com/v1/badges/hardbyte/python-can&style=flat
45-
:target: https://mergify.io
46-
:alt: Mergify Status
47-
4844
The **C**\ ontroller **A**\ rea **N**\ etwork is a bus standard designed
4945
to allow microcontrollers and devices to communicate with each other. It
5046
has priority based bus arbitration and reliable deterministic
@@ -64,6 +60,7 @@ Library Version Python
6460
3.x 2.7+, 3.5+
6561
4.0+ 3.7+
6662
4.3+ 3.8+
63+
4.6+ 3.9+
6764
============================== ===========
6865

6966

can/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
import contextlib
99
import logging
1010
from importlib.metadata import PackageNotFoundError, version
11-
from typing import Any, Dict
11+
from typing import Any
1212

1313
__all__ = [
1414
"VALID_INTERFACES",
@@ -130,4 +130,4 @@
130130

131131
log = logging.getLogger("can")
132132

133-
rc: Dict[str, Any] = {}
133+
rc: dict[str, Any] = {}

can/_entry_points.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
import sys
33
from dataclasses import dataclass
44
from importlib.metadata import entry_points
5-
from typing import Any, List
5+
from typing import Any
66

77

88
@dataclass
@@ -20,14 +20,14 @@ def load(self) -> Any:
2020
# "Compatibility Note".
2121
if sys.version_info >= (3, 10):
2222

23-
def read_entry_points(group: str) -> List[_EntryPoint]:
23+
def read_entry_points(group: str) -> list[_EntryPoint]:
2424
return [
2525
_EntryPoint(ep.name, ep.module, ep.attr) for ep in entry_points(group=group)
2626
]
2727

2828
else:
2929

30-
def read_entry_points(group: str) -> List[_EntryPoint]:
30+
def read_entry_points(group: str) -> list[_EntryPoint]:
3131
return [
3232
_EntryPoint(ep.name, *ep.value.split(":", maxsplit=1))
3333
for ep in entry_points().get(group, [])

can/bit_timing.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# pylint: disable=too-many-lines
22
import math
3-
from typing import TYPE_CHECKING, Iterator, List, Mapping, cast
3+
from collections.abc import Iterator, Mapping
4+
from typing import TYPE_CHECKING, cast
45

56
if TYPE_CHECKING:
67
from can.typechecking import BitTimingDict, BitTimingFdDict
@@ -286,7 +287,7 @@ def from_sample_point(
286287
if sample_point < 50.0:
287288
raise ValueError(f"sample_point (={sample_point}) must not be below 50%.")
288289

289-
possible_solutions: List[BitTiming] = list(
290+
possible_solutions: list[BitTiming] = list(
290291
cls.iterate_from_sample_point(f_clock, bitrate, sample_point)
291292
)
292293

@@ -874,7 +875,7 @@ def from_sample_point(
874875
f"data_sample_point (={data_sample_point}) must not be below 50%."
875876
)
876877

877-
possible_solutions: List[BitTimingFd] = list(
878+
possible_solutions: list[BitTimingFd] = list(
878879
cls.iterate_from_sample_point(
879880
f_clock,
880881
nom_bitrate,

can/broadcastmanager.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,12 @@
1212
import threading
1313
import time
1414
import warnings
15+
from collections.abc import Sequence
1516
from typing import (
1617
TYPE_CHECKING,
1718
Callable,
1819
Final,
1920
Optional,
20-
Sequence,
21-
Tuple,
2221
Union,
2322
cast,
2423
)
@@ -127,7 +126,7 @@ def __init__(
127126
@staticmethod
128127
def _check_and_convert_messages(
129128
messages: Union[Sequence[Message], Message],
130-
) -> Tuple[Message, ...]:
129+
) -> tuple[Message, ...]:
131130
"""Helper function to convert a Message or Sequence of messages into a
132131
tuple, and raises an error when the given value is invalid.
133132
@@ -194,7 +193,7 @@ def start(self) -> None:
194193

195194

196195
class ModifiableCyclicTaskABC(CyclicSendTaskABC, abc.ABC):
197-
def _check_modified_messages(self, messages: Tuple[Message, ...]) -> None:
196+
def _check_modified_messages(self, messages: tuple[Message, ...]) -> None:
198197
"""Helper function to perform error checking when modifying the data in
199198
the cyclic task.
200199

can/bus.py

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,14 @@
66
import logging
77
import threading
88
from abc import ABC, ABCMeta, abstractmethod
9+
from collections.abc import Iterator, Sequence
910
from enum import Enum, auto
1011
from time import time
1112
from types import TracebackType
1213
from typing import (
1314
Any,
1415
Callable,
15-
Iterator,
16-
List,
1716
Optional,
18-
Sequence,
19-
Tuple,
20-
Type,
2117
Union,
2218
cast,
2319
)
@@ -97,7 +93,7 @@ def __init__(
9793
:raises ~can.exceptions.CanInitializationError:
9894
If the bus cannot be initialized
9995
"""
100-
self._periodic_tasks: List[_SelfRemovingCyclicTask] = []
96+
self._periodic_tasks: list[_SelfRemovingCyclicTask] = []
10197
self.set_filters(can_filters)
10298
# Flip the class default value when the constructor finishes. That
10399
# usually means the derived class constructor was also successful,
@@ -147,7 +143,7 @@ def recv(self, timeout: Optional[float] = None) -> Optional[Message]:
147143

148144
def _recv_internal(
149145
self, timeout: Optional[float]
150-
) -> Tuple[Optional[Message], bool]:
146+
) -> tuple[Optional[Message], bool]:
151147
"""
152148
Read a message from the bus and tell whether it was filtered.
153149
This methods may be called by :meth:`~can.BusABC.recv`
@@ -491,7 +487,7 @@ def __enter__(self) -> Self:
491487

492488
def __exit__(
493489
self,
494-
exc_type: Optional[Type[BaseException]],
490+
exc_type: Optional[type[BaseException]],
495491
exc_value: Optional[BaseException],
496492
traceback: Optional[TracebackType],
497493
) -> None:
@@ -529,7 +525,7 @@ def protocol(self) -> CanProtocol:
529525
return self._can_protocol
530526

531527
@staticmethod
532-
def _detect_available_configs() -> List[can.typechecking.AutoDetectedConfig]:
528+
def _detect_available_configs() -> list[can.typechecking.AutoDetectedConfig]:
533529
"""Detect all configurations/channels that this interface could
534530
currently connect with.
535531

can/ctypesutil.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
import ctypes
66
import logging
77
import sys
8-
from typing import Any, Callable, Optional, Tuple, Union
8+
from typing import Any, Callable, Optional, Union
99

1010
log = logging.getLogger("can.ctypesutil")
1111

@@ -32,7 +32,7 @@ def map_symbol(
3232
self,
3333
func_name: str,
3434
restype: Any = None,
35-
argtypes: Tuple[Any, ...] = (),
35+
argtypes: tuple[Any, ...] = (),
3636
errcheck: Optional[Callable[..., Any]] = None,
3737
) -> Any:
3838
"""

can/exceptions.py

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -15,14 +15,9 @@
1515
:class:`ValueError`. This should always be documented for the function at hand.
1616
"""
1717

18-
import sys
18+
from collections.abc import Generator
1919
from contextlib import contextmanager
20-
from typing import Optional, Type
21-
22-
if sys.version_info >= (3, 9):
23-
from collections.abc import Generator
24-
else:
25-
from typing import Generator
20+
from typing import Optional
2621

2722

2823
class CanError(Exception):
@@ -114,7 +109,7 @@ class CanTimeoutError(CanError, TimeoutError):
114109
@contextmanager
115110
def error_check(
116111
error_message: Optional[str] = None,
117-
exception_type: Type[CanError] = CanOperationError,
112+
exception_type: type[CanError] = CanOperationError,
118113
) -> Generator[None, None, None]:
119114
"""Catches any exceptions and turns them into the new type while preserving the stack trace."""
120115
try:

can/interface.py

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@
66

77
import importlib
88
import logging
9-
from typing import Any, Iterable, List, Optional, Type, Union, cast
9+
from collections.abc import Iterable
10+
from typing import Any, Optional, Union, cast
1011

1112
from . import util
1213
from .bus import BusABC
@@ -18,7 +19,7 @@
1819
log_autodetect = log.getChild("detect_available_configs")
1920

2021

21-
def _get_class_for_interface(interface: str) -> Type[BusABC]:
22+
def _get_class_for_interface(interface: str) -> type[BusABC]:
2223
"""
2324
Returns the main bus class for the given interface.
2425
@@ -52,7 +53,7 @@ def _get_class_for_interface(interface: str) -> Type[BusABC]:
5253
f"'{interface}': {e}"
5354
) from None
5455

55-
return cast("Type[BusABC]", bus_class)
56+
return cast("type[BusABC]", bus_class)
5657

5758

5859
@util.deprecated_args_alias(
@@ -139,7 +140,7 @@ def Bus( # noqa: N802
139140

140141
def detect_available_configs(
141142
interfaces: Union[None, str, Iterable[str]] = None,
142-
) -> List[AutoDetectedConfig]:
143+
) -> list[AutoDetectedConfig]:
143144
"""Detect all configurations/channels that the interfaces could
144145
currently connect with.
145146

0 commit comments

Comments
 (0)