Skip to content

Commit 566f6f6

Browse files
authored
Solve python3.14 problem (and mypy upgrade). (#2814)
1 parent ca41c04 commit 566f6f6

File tree

3 files changed

+39
-38
lines changed

3 files changed

+39
-38
lines changed

examples/package_test_tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ def callback_new_connection(self) -> ModbusProtocol:
103103
return new_stub
104104

105105

106-
test_port = 5004 # pylint: disable=invalid-name
106+
test_port = 5004
107107

108108
class ClientTester: # pylint: disable=too-few-public-methods
109109
"""Main program."""

pymodbus/pdu/device.py

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ class ModbusPlusStatistics:
3434
For more information, see the modbus implementation guide page 87.
3535
"""
3636

37-
__data = OrderedDict(
37+
stat_data = OrderedDict(
3838
{
3939
"node_type_id": [0x00] * 2, # 00
4040
"software_version_number": [0x00] * 2, # 01
@@ -95,26 +95,26 @@ def __iter__(self):
9595
9696
:returns: An iterator of the modbus plus statistics
9797
"""
98-
return iter(self.__data.items())
98+
return iter(self.stat_data.items())
9999

100100
def reset(self):
101101
"""Clear all of the modbus plus statistics."""
102-
for key in self.__data:
103-
self.__data[key] = [0x00] * len(self.__data[key])
102+
for key in self.stat_data:
103+
self.stat_data[key] = [0x00] * len(self.stat_data[key])
104104

105105
def summary(self):
106106
"""Return a summary of the modbus plus statistics.
107107
108108
:returns: 54 16-bit words representing the status
109109
"""
110-
return iter(self.__data.values())
110+
return iter(self.stat_data.values())
111111

112112
def encode(self):
113113
"""Return a summary of the modbus plus statistics.
114114
115115
:returns: 54 16-bit words representing the status
116116
"""
117-
total, values = [], sum(self.__data.values(), []) # noqa: RUF017
117+
total, values = [], sum(self.stat_data.values(), []) # noqa: RUF017
118118
for i in range(0, len(values), 2):
119119
total.append((values[i] << 8) | values[i + 1])
120120
return total
@@ -132,7 +132,7 @@ class ModbusDeviceIdentification:
132132
application protocol.
133133
"""
134134

135-
__data = {
135+
stat_data = {
136136
0x00: "", # VendorName
137137
0x01: "", # ProductCode
138138
0x02: "", # MajorMinorRevision
@@ -166,26 +166,26 @@ def __init__(self, info=None, info_name=None):
166166
if isinstance(info_name, dict):
167167
for key in info_name:
168168
inx = self.__names.index(key)
169-
self.__data[inx] = info_name[key]
169+
self.stat_data[inx] = info_name[key]
170170

171171
if isinstance(info, dict):
172172
for key in info:
173173
if (0x06 >= key >= 0x00) or (0xFF >= key >= 0x80):
174-
self.__data[key] = info[key]
174+
self.stat_data[key] = info[key]
175175

176176
def __iter__(self):
177177
"""Iterate over the device information.
178178
179179
:returns: An iterator of the device information
180180
"""
181-
return iter(self.__data.items())
181+
return iter(self.stat_data.items())
182182

183183
def summary(self):
184184
"""Return a summary of the main items.
185185
186186
:returns: An dictionary of the main items
187187
"""
188-
return dict(zip(self.__names, iter(self.__data.values())))
188+
return dict(zip(self.__names, iter(self.stat_data.values())))
189189

190190
def update(self, value):
191191
"""Update the values of this identity.
@@ -194,7 +194,7 @@ def update(self, value):
194194
195195
:param value: The value to copy values from
196196
"""
197-
self.__data.update(value)
197+
self.stat_data.update(value)
198198

199199
def __setitem__(self, key, value):
200200
"""Access the device information.
@@ -203,14 +203,14 @@ def __setitem__(self, key, value):
203203
:param value: The new value for referenced register
204204
"""
205205
if key not in [0x07, 0x08]:
206-
self.__data[key] = value
206+
self.stat_data[key] = value
207207

208208
def __getitem__(self, key):
209209
"""Access the device information.
210210
211211
:param key: The register to read
212212
"""
213-
return self.__data.setdefault(key, "")
213+
return self.stat_data.setdefault(key, "")
214214

215215
def __str__(self):
216216
"""Build a representation of the device.
@@ -223,13 +223,13 @@ def __str__(self):
223223
# Properties
224224
# -------------------------------------------------------------------------#
225225
# fmt: off
226-
VendorName = dict_property(lambda s: s.__data, 0)
227-
ProductCode = dict_property(lambda s: s.__data, 1)
228-
MajorMinorRevision = dict_property(lambda s: s.__data, 2)
229-
VendorUrl = dict_property(lambda s: s.__data, 3)
230-
ProductName = dict_property(lambda s: s.__data, 4)
231-
ModelName = dict_property(lambda s: s.__data, 5)
232-
UserApplicationName = dict_property(lambda s: s.__data, 6)
226+
VendorName = dict_property(lambda s: s.stat_data, 0)
227+
ProductCode = dict_property(lambda s: s.stat_data, 1)
228+
MajorMinorRevision = dict_property(lambda s: s.stat_data, 2)
229+
VendorUrl = dict_property(lambda s: s.stat_data, 3)
230+
ProductName = dict_property(lambda s: s.stat_data, 4)
231+
ModelName = dict_property(lambda s: s.stat_data, 5)
232+
UserApplicationName = dict_property(lambda s: s.stat_data, 6)
233233
# fmt: on
234234

235235

@@ -363,7 +363,7 @@ class ModbusCountersHandler:
363363
.. note:: I threw the event counter in here for convenience
364364
"""
365365

366-
__data = dict.fromkeys(range(9), 0x00)
366+
stat_data = dict.fromkeys(range(9), 0x00)
367367
__names = [
368368
"BusMessage",
369369
"BusCommunicationError",
@@ -380,7 +380,7 @@ def __iter__(self):
380380
381381
:returns: An iterator of the device counters
382382
"""
383-
return zip(self.__names, iter(self.__data.values()))
383+
return zip(self.__names, iter(self.stat_data.values()))
384384

385385
def update(self, values):
386386
"""Update the values of this identity.
@@ -397,15 +397,15 @@ def update(self, values):
397397

398398
def reset(self):
399399
"""Clear all of the system counters."""
400-
self.__data = dict.fromkeys(range(9), 0x00)
400+
self.stat_data = dict.fromkeys(range(9), 0x00)
401401

402402
def summary(self):
403403
"""Return a summary of the counters current status.
404404
405405
:returns: A byte with each bit representing each counter
406406
"""
407407
count, result = 0x01, 0x00
408-
for i in iter(self.__data.values()):
408+
for i in iter(self.stat_data.values()):
409409
if i != 0x00: # pylint: disable=compare-to-zero
410410
result |= count
411411
count <<= 1
@@ -415,15 +415,15 @@ def summary(self):
415415
# Properties
416416
# -------------------------------------------------------------------------#
417417
# fmt: off
418-
BusMessage = dict_property(lambda s: s.__data, 0)
419-
BusCommunicationError = dict_property(lambda s: s.__data, 1)
420-
BusExceptionError = dict_property(lambda s: s.__data, 2)
421-
DeviceMessage = dict_property(lambda s: s.__data, 3)
422-
DeviceNoResponse = dict_property(lambda s: s.__data, 4)
423-
DeviceNAK = dict_property(lambda s: s.__data, 5)
424-
DEVICE_BUSY = dict_property(lambda s: s.__data, 6)
425-
BusCharacterOverrun = dict_property(lambda s: s.__data, 7)
426-
Event = dict_property(lambda s: s.__data, 8)
418+
BusMessage = dict_property(lambda s: s.stat_data, 0)
419+
BusCommunicationError = dict_property(lambda s: s.stat_data, 1)
420+
BusExceptionError = dict_property(lambda s: s.stat_data, 2)
421+
DeviceMessage = dict_property(lambda s: s.stat_data, 3)
422+
DeviceNoResponse = dict_property(lambda s: s.stat_data, 4)
423+
DeviceNAK = dict_property(lambda s: s.stat_data, 5)
424+
DEVICE_BUSY = dict_property(lambda s: s.stat_data, 6)
425+
BusCharacterOverrun = dict_property(lambda s: s.stat_data, 7)
426+
Event = dict_property(lambda s: s.stat_data, 8)
427427
# fmt: on
428428

429429

pymodbus/transport/transport.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -257,9 +257,10 @@ async def listen(self) -> bool:
257257
self.is_closing = False
258258
self.is_listener = True
259259
try:
260-
self.transport = await self.call_create()
261-
if isinstance(self.transport, tuple):
262-
self.transport = self.transport[0]
260+
new_transport = await self.call_create()
261+
if isinstance(new_transport, tuple):
262+
new_transport = new_transport[0]
263+
self.transport = new_transport
263264
except OSError as exc:
264265
Log.warning("Failed to start server {}", exc)
265266
self.__close()

0 commit comments

Comments
 (0)