Skip to content

Commit 237f2be

Browse files
authored
Update linters, activate more ruff rules (#1669)
* update ruff to 0.0.286 * activate pyflakes rules * activate flake8-type-checking * activate Ruff-specific rules * activate pylint rules * activate flake8-comprehensions * update ruff to 0.0.292 * remove unnecessary tuple() call * update mypy to 1.5.*, update black to 23.9.* --------- Co-authored-by: zariiii9003 <[email protected]>
1 parent 3c3f123 commit 237f2be

22 files changed

+133
-140
lines changed

can/bit_timing.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
# pylint: disable=too-many-lines
22
import math
3-
from typing import Iterator, List, Mapping, cast
3+
from typing import TYPE_CHECKING, Iterator, List, Mapping, cast
44

5-
from can.typechecking import BitTimingDict, BitTimingFdDict
5+
if TYPE_CHECKING:
6+
from can.typechecking import BitTimingDict, BitTimingFdDict
67

78

89
class BitTiming(Mapping):

can/interfaces/gs_usb.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ def __init__(
3535
"""
3636
if (index is not None) and ((bus or address) is not None):
3737
raise CanInitializationError(
38-
f"index and bus/address cannot be used simultaneously"
38+
"index and bus/address cannot be used simultaneously"
3939
)
4040

4141
if index is not None:

can/interfaces/ics_neovi/neovi_bus.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -302,15 +302,15 @@ def _find_device(self, type_filter=None, serial=None):
302302
for device in devices:
303303
if serial is None or self.get_serial_number(device) == str(serial):
304304
return device
305-
else:
306-
msg = ["No device"]
307-
308-
if type_filter is not None:
309-
msg.append(f"with type {type_filter}")
310-
if serial is not None:
311-
msg.append(f"with serial {serial}")
312-
msg.append("found.")
313-
raise CanInitializationError(" ".join(msg))
305+
306+
msg = ["No device"]
307+
308+
if type_filter is not None:
309+
msg.append(f"with type {type_filter}")
310+
if serial is not None:
311+
msg.append(f"with serial {serial}")
312+
msg.append("found.")
313+
raise CanInitializationError(" ".join(msg))
314314

315315
def _process_msg_queue(self, timeout=0.1):
316316
try:

can/interfaces/ixxat/canlib.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -28,17 +28,17 @@ def __init__(
2828
unique_hardware_id: Optional[int] = None,
2929
extended: bool = True,
3030
fd: bool = False,
31-
rx_fifo_size: int = None,
32-
tx_fifo_size: int = None,
31+
rx_fifo_size: Optional[int] = None,
32+
tx_fifo_size: Optional[int] = None,
3333
bitrate: int = 500000,
3434
data_bitrate: int = 2000000,
35-
sjw_abr: int = None,
36-
tseg1_abr: int = None,
37-
tseg2_abr: int = None,
38-
sjw_dbr: int = None,
39-
tseg1_dbr: int = None,
40-
tseg2_dbr: int = None,
41-
ssp_dbr: int = None,
35+
sjw_abr: Optional[int] = None,
36+
tseg1_abr: Optional[int] = None,
37+
tseg2_abr: Optional[int] = None,
38+
sjw_dbr: Optional[int] = None,
39+
tseg1_dbr: Optional[int] = None,
40+
tseg2_dbr: Optional[int] = None,
41+
ssp_dbr: Optional[int] = None,
4242
**kwargs,
4343
):
4444
"""

can/interfaces/ixxat/canlib_vcinpl2.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -436,13 +436,13 @@ def __init__(
436436
tx_fifo_size: int = 128,
437437
bitrate: int = 500000,
438438
data_bitrate: int = 2000000,
439-
sjw_abr: int = None,
440-
tseg1_abr: int = None,
441-
tseg2_abr: int = None,
442-
sjw_dbr: int = None,
443-
tseg1_dbr: int = None,
444-
tseg2_dbr: int = None,
445-
ssp_dbr: int = None,
439+
sjw_abr: Optional[int] = None,
440+
tseg1_abr: Optional[int] = None,
441+
tseg2_abr: Optional[int] = None,
442+
sjw_dbr: Optional[int] = None,
443+
tseg1_dbr: Optional[int] = None,
444+
tseg2_dbr: Optional[int] = None,
445+
ssp_dbr: Optional[int] = None,
446446
**kwargs,
447447
):
448448
"""

can/interfaces/pcan/basic.py

Lines changed: 47 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -297,73 +297,63 @@
297297

298298
# PCAN parameter values
299299
#
300-
PCAN_PARAMETER_OFF = int(0x00) # The PCAN parameter is not set (inactive)
301-
PCAN_PARAMETER_ON = int(0x01) # The PCAN parameter is set (active)
302-
PCAN_FILTER_CLOSE = int(0x00) # The PCAN filter is closed. No messages will be received
303-
PCAN_FILTER_OPEN = int(
304-
0x01
305-
) # The PCAN filter is fully opened. All messages will be received
306-
PCAN_FILTER_CUSTOM = int(
307-
0x02
308-
) # The PCAN filter is custom configured. Only registered messages will be received
309-
PCAN_CHANNEL_UNAVAILABLE = int(
310-
0x00
311-
) # The PCAN-Channel handle is illegal, or its associated hardware is not available
312-
PCAN_CHANNEL_AVAILABLE = int(
313-
0x01
314-
) # The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in)
315-
PCAN_CHANNEL_OCCUPIED = int(
316-
0x02
317-
) # The PCAN-Channel handle is valid, and is already being used
300+
PCAN_PARAMETER_OFF = 0x00 # The PCAN parameter is not set (inactive)
301+
PCAN_PARAMETER_ON = 0x01 # The PCAN parameter is set (active)
302+
PCAN_FILTER_CLOSE = 0x00 # The PCAN filter is closed. No messages will be received
303+
PCAN_FILTER_OPEN = (
304+
0x01 # The PCAN filter is fully opened. All messages will be received
305+
)
306+
PCAN_FILTER_CUSTOM = 0x02 # The PCAN filter is custom configured. Only registered messages will be received
307+
PCAN_CHANNEL_UNAVAILABLE = 0x00 # The PCAN-Channel handle is illegal, or its associated hardware is not available
308+
PCAN_CHANNEL_AVAILABLE = 0x01 # The PCAN-Channel handle is available to be connected (PnP Hardware: it means furthermore that the hardware is plugged-in)
309+
PCAN_CHANNEL_OCCUPIED = (
310+
0x02 # The PCAN-Channel handle is valid, and is already being used
311+
)
318312
PCAN_CHANNEL_PCANVIEW = (
319313
PCAN_CHANNEL_AVAILABLE | PCAN_CHANNEL_OCCUPIED
320314
) # The PCAN-Channel handle is already being used by a PCAN-View application, but is available to connect
321315

322-
LOG_FUNCTION_DEFAULT = int(0x00) # Logs system exceptions / errors
323-
LOG_FUNCTION_ENTRY = int(0x01) # Logs the entries to the PCAN-Basic API functions
324-
LOG_FUNCTION_PARAMETERS = int(
325-
0x02
326-
) # Logs the parameters passed to the PCAN-Basic API functions
327-
LOG_FUNCTION_LEAVE = int(0x04) # Logs the exits from the PCAN-Basic API functions
328-
LOG_FUNCTION_WRITE = int(0x08) # Logs the CAN messages passed to the CAN_Write function
329-
LOG_FUNCTION_READ = int(
330-
0x10
331-
) # Logs the CAN messages received within the CAN_Read function
332-
LOG_FUNCTION_ALL = int(
333-
0xFFFF
334-
) # Logs all possible information within the PCAN-Basic API functions
316+
LOG_FUNCTION_DEFAULT = 0x00 # Logs system exceptions / errors
317+
LOG_FUNCTION_ENTRY = 0x01 # Logs the entries to the PCAN-Basic API functions
318+
LOG_FUNCTION_PARAMETERS = (
319+
0x02 # Logs the parameters passed to the PCAN-Basic API functions
320+
)
321+
LOG_FUNCTION_LEAVE = 0x04 # Logs the exits from the PCAN-Basic API functions
322+
LOG_FUNCTION_WRITE = 0x08 # Logs the CAN messages passed to the CAN_Write function
323+
LOG_FUNCTION_READ = 0x10 # Logs the CAN messages received within the CAN_Read function
324+
LOG_FUNCTION_ALL = (
325+
0xFFFF # Logs all possible information within the PCAN-Basic API functions
326+
)
335327

336-
TRACE_FILE_SINGLE = int(
337-
0x00
338-
) # A single file is written until it size reaches PAN_TRACE_SIZE
339-
TRACE_FILE_SEGMENTED = int(
340-
0x01
341-
) # Traced data is distributed in several files with size PAN_TRACE_SIZE
342-
TRACE_FILE_DATE = int(0x02) # Includes the date into the name of the trace file
343-
TRACE_FILE_TIME = int(0x04) # Includes the start time into the name of the trace file
344-
TRACE_FILE_OVERWRITE = int(
345-
0x80
346-
) # Causes the overwriting of available traces (same name)
328+
TRACE_FILE_SINGLE = (
329+
0x00 # A single file is written until it size reaches PAN_TRACE_SIZE
330+
)
331+
TRACE_FILE_SEGMENTED = (
332+
0x01 # Traced data is distributed in several files with size PAN_TRACE_SIZE
333+
)
334+
TRACE_FILE_DATE = 0x02 # Includes the date into the name of the trace file
335+
TRACE_FILE_TIME = 0x04 # Includes the start time into the name of the trace file
336+
TRACE_FILE_OVERWRITE = 0x80 # Causes the overwriting of available traces (same name)
347337

348-
FEATURE_FD_CAPABLE = int(0x01) # Device supports flexible data-rate (CAN-FD)
349-
FEATURE_DELAY_CAPABLE = int(
350-
0x02
351-
) # Device supports a delay between sending frames (FPGA based USB devices)
352-
FEATURE_IO_CAPABLE = int(
353-
0x04
354-
) # Device supports I/O functionality for electronic circuits (USB-Chip devices)
338+
FEATURE_FD_CAPABLE = 0x01 # Device supports flexible data-rate (CAN-FD)
339+
FEATURE_DELAY_CAPABLE = (
340+
0x02 # Device supports a delay between sending frames (FPGA based USB devices)
341+
)
342+
FEATURE_IO_CAPABLE = (
343+
0x04 # Device supports I/O functionality for electronic circuits (USB-Chip devices)
344+
)
355345

356-
SERVICE_STATUS_STOPPED = int(0x01) # The service is not running
357-
SERVICE_STATUS_RUNNING = int(0x04) # The service is running
346+
SERVICE_STATUS_STOPPED = 0x01 # The service is not running
347+
SERVICE_STATUS_RUNNING = 0x04 # The service is running
358348

359349
# Other constants
360350
#
361-
MAX_LENGTH_HARDWARE_NAME = int(
362-
33
363-
) # Maximum length of the name of a device: 32 characters + terminator
364-
MAX_LENGTH_VERSION_STRING = int(
365-
256
366-
) # Maximum length of a version string: 255 characters + terminator
351+
MAX_LENGTH_HARDWARE_NAME = (
352+
33 # Maximum length of the name of a device: 32 characters + terminator
353+
)
354+
MAX_LENGTH_VERSION_STRING = (
355+
256 # Maximum length of a version string: 255 characters + terminator
356+
)
367357

368358
# PCAN message types
369359
#

can/interfaces/pcan/pcan.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@
8585
boottimeEpoch = 0
8686
else:
8787
boottimeEpoch = uptime.boottime().timestamp()
88-
except ImportError as error:
88+
except ImportError:
8989
log.warning(
9090
"uptime library not available, timestamps are relative to boot time and not to Epoch UTC",
9191
)
@@ -283,7 +283,7 @@ def __init__(
283283
clock_param = "f_clock" if "f_clock" in kwargs else "f_clock_mhz"
284284
fd_parameters_values = [
285285
f"{key}={kwargs[key]}"
286-
for key in (clock_param,) + PCAN_FD_PARAMETER_LIST
286+
for key in (clock_param, *PCAN_FD_PARAMETER_LIST)
287287
if key in kwargs
288288
]
289289

@@ -413,7 +413,7 @@ def bits(n):
413413
def get_api_version(self):
414414
error, value = self.m_objPCANBasic.GetValue(PCAN_NONEBUS, PCAN_API_VERSION)
415415
if error != PCAN_ERROR_OK:
416-
raise CanInitializationError(f"Failed to read pcan basic api version")
416+
raise CanInitializationError("Failed to read pcan basic api version")
417417

418418
# fix https://github.com/hardbyte/python-can/issues/1642
419419
version_string = value.decode("ascii").replace(",", ".").replace(" ", "")

can/interfaces/socketcand/socketcand.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ def __init__(self, channel, host, port, can_filters=None, **kwargs):
9191
)
9292
self._tcp_send(f"< open {channel} >")
9393
self._expect_msg("< ok >")
94-
self._tcp_send(f"< rawmode >")
94+
self._tcp_send("< rawmode >")
9595
self._expect_msg("< ok >")
9696
super().__init__(channel=channel, can_filters=can_filters, **kwargs)
9797

can/interfaces/systec/ucan.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ def init_hardware(self, serial=None, device_number=ANY_MODULE):
409409
Initializes the device with the corresponding serial or device number.
410410
411411
:param int or None serial: Serial number of the USB-CANmodul.
412-
:param int device_number: Device number (0 254, or :const:`ANY_MODULE` for the first device).
412+
:param int device_number: Device number (0 - 254, or :const:`ANY_MODULE` for the first device).
413413
"""
414414
if not self._hw_is_initialized:
415415
# initialize hardware either by device number or serial

can/interfaces/vector/canlib.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -69,19 +69,17 @@
6969
class VectorBus(BusABC):
7070
"""The CAN Bus implemented for the Vector interface."""
7171

72-
deprecated_args = dict(
73-
sjwAbr="sjw_abr",
74-
tseg1Abr="tseg1_abr",
75-
tseg2Abr="tseg2_abr",
76-
sjwDbr="sjw_dbr",
77-
tseg1Dbr="tseg1_dbr",
78-
tseg2Dbr="tseg2_dbr",
79-
)
80-
8172
@deprecated_args_alias(
8273
deprecation_start="4.0.0",
8374
deprecation_end="5.0.0",
84-
**deprecated_args,
75+
**{
76+
"sjwAbr": "sjw_abr",
77+
"tseg1Abr": "tseg1_abr",
78+
"tseg2Abr": "tseg2_abr",
79+
"sjwDbr": "sjw_dbr",
80+
"tseg1Dbr": "tseg1_dbr",
81+
"tseg2Dbr": "tseg2_dbr",
82+
},
8583
)
8684
def __init__(
8785
self,

0 commit comments

Comments
 (0)