Skip to content

Commit 20a2556

Browse files
authored
Enable pyupgrade (U) rules in ruff (#1484)
1 parent 103b495 commit 20a2556

File tree

6 files changed

+13
-19
lines changed

6 files changed

+13
-19
lines changed

pymodbus/client/base.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import asyncio
55
import socket
66
from dataclasses import dataclass
7-
from typing import Any, Callable, Optional, Tuple, Type
7+
from typing import Any, Callable
88

99
from pymodbus.client.mixin import ModbusClientMixin
1010
from pymodbus.constants import Defaults
@@ -70,7 +70,7 @@ class _params: # pylint: disable=too-many-instance-attributes
7070

7171
host: str = None
7272
port: str | int = None
73-
framer: Type[ModbusFramer] = None
73+
framer: type[ModbusFramer] = None
7474
timeout: float = None
7575
retries: int = None
7676
retry_on_empty: bool = None
@@ -80,15 +80,15 @@ class _params: # pylint: disable=too-many-instance-attributes
8080
kwargs: dict = None
8181
reconnect_delay: int = None
8282
reconnect_delay_max: int = None
83-
on_reconnect_callback: Optional[Callable[[], None]] = None
83+
on_reconnect_callback: Callable[[], None] | None = None
8484

8585
baudrate: int = None
8686
bytesize: int = None
8787
parity: str = None
8888
stopbits: int = None
8989
handle_local_echo: bool = None
9090

91-
source_address: Tuple[str, int] = None
91+
source_address: tuple[str, int] = None
9292

9393
sslctx: str = None
9494
certfile: str = None
@@ -98,7 +98,7 @@ class _params: # pylint: disable=too-many-instance-attributes
9898

9999
def __init__( # pylint: disable=too-many-arguments
100100
self,
101-
framer: Type[ModbusFramer] = None,
101+
framer: type[ModbusFramer] = None,
102102
timeout: str | float = Defaults.Timeout,
103103
retries: str | int = Defaults.Retries,
104104
retry_on_empty: bool = Defaults.RetryOnEmpty,
@@ -107,7 +107,7 @@ def __init__( # pylint: disable=too-many-arguments
107107
broadcast_enable: bool = Defaults.BroadcastEnable,
108108
reconnect_delay: int = Defaults.ReconnectDelay,
109109
reconnect_delay_max: int = Defaults.ReconnectDelayMax,
110-
on_reconnect_callback: Optional[Callable[[], None]] = None,
110+
on_reconnect_callback: Callable[[], None] | None = None,
111111
**kwargs: Any,
112112
) -> None:
113113
"""Initialize a client instance."""

pymodbus/client/serial.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,7 +220,7 @@ def __init__(
220220

221221
self.last_frame_end = None
222222

223-
self._t0 = float((1 + 8 + 2)) / self.params.baudrate
223+
self._t0 = float(1 + 8 + 2) / self.params.baudrate
224224

225225
"""
226226
The minimum delay is 0.01s and the maximum can be set to 0.05s.

pymodbus/factory.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -202,7 +202,7 @@ def _helper(self, data):
202202
Log.debug("Factory Request[{}]", function_code)
203203
request = IllegalFunctionRequest(function_code)
204204
else:
205-
fc_string = "%s: %s" % ( # pylint: disable=consider-using-f-string
205+
fc_string = "{}: {}".format( # pylint: disable=consider-using-f-string
206206
str(self.lookup[function_code]) # pylint: disable=use-maxsplit-arg
207207
.split(".")[-1]
208208
.rstrip('">"'),
@@ -331,7 +331,7 @@ def _helper(self, data):
331331
"""
332332
fc_string = function_code = int(data[0])
333333
if function_code in self.lookup:
334-
fc_string = "%s: %s" % ( # pylint: disable=consider-using-f-string
334+
fc_string = "{}: {}".format( # pylint: disable=consider-using-f-string
335335
str(self.lookup[function_code]) # pylint: disable=use-maxsplit-arg
336336
.split(".")[-1]
337337
.rstrip('">"'),

pymodbus/framer/ascii_framer.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -196,15 +196,10 @@ def buildPacket(self, message):
196196
checksum = computeLRC(encoded + buffer)
197197

198198
packet = bytearray()
199-
params = (message.slave_id, message.function_code)
200199
packet.extend(self._start)
201-
packet.extend(
202-
("%02x%02x" % params).encode() # pylint: disable=consider-using-f-string
203-
)
200+
packet.extend(f"{message.slave_id:02x}{message.function_code:02x}".encode())
204201
packet.extend(b2a_hex(encoded))
205-
packet.extend(
206-
("%02x" % checksum).encode() # pylint: disable=consider-using-f-string
207-
)
202+
packet.extend(f"{checksum:02x}".encode())
208203
packet.extend(self._end)
209204
return bytes(packet).upper()
210205

pymodbus/payload.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,7 @@ def _pack_words(self, fstring, value):
6767
:param value: Value to be packed
6868
:return:
6969
"""
70-
value = pack(
71-
"!{}".format(fstring), value # pylint: disable=consider-using-f-string
72-
)
70+
value = pack(f"!{fstring}", value)
7371
wordorder = WC.get(fstring.lower()) // 2
7472
upperbyte = f"!{wordorder}H"
7573
payload = unpack(upperbyte, value)

ruff.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ select = [
2626
"SIM300",
2727
"SIM401",
2828
"RUF",
29+
"U",
2930
]
3031
[pydocstyle]
3132
convention = "pep257"

0 commit comments

Comments
 (0)