Skip to content

Commit c0621c7

Browse files
committed
Limit use of Singleton.
1 parent b884f71 commit c0621c7

File tree

3 files changed

+34
-11
lines changed

3 files changed

+34
-11
lines changed

pymodbus/client/mixin.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import pymodbus.other_message as pdu_other_msg
1010
import pymodbus.register_read_message as pdu_reg_read
1111
import pymodbus.register_write_message as pdu_req_write
12+
from pymodbus.constants import INTERNAL_ERROR
1213
from pymodbus.exceptions import ModbusException
1314
from pymodbus.pdu import ModbusRequest, ModbusResponse
1415

@@ -53,7 +54,7 @@ def execute(self, request: ModbusRequest) -> ModbusResponse:
5354
.. tip::
5455
Response is not interpreted.
5556
"""
56-
raise ModbusException("Pymodbus internal ERROR")
57+
raise ModbusException(INTERNAL_ERROR)
5758

5859
def read_coils(
5960
self, address: int, count: int = 1, slave: int = 0, **kwargs: Any

pymodbus/constants.py

Lines changed: 31 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,10 @@
44
values for the servers and clients.
55
"""
66

7+
INTERNAL_ERROR = "Pymodbus internal error"
78

8-
from pymodbus.interfaces import Singleton
99

10-
11-
class Defaults(Singleton): # pylint: disable=too-few-public-methods
10+
class Defaults: # pylint: disable=too-few-public-methods
1211
"""A collection of modbus default values.
1312
1413
.. attribute:: Port
@@ -155,8 +154,12 @@ class Defaults(Singleton): # pylint: disable=too-few-public-methods
155154
ReconnectDelayMax = 1000 * 60 * 5
156155
Count = 1
157156

157+
def __init__(self):
158+
"""Prohibit objects."""
159+
raise RuntimeError(INTERNAL_ERROR)
160+
158161

159-
class ModbusStatus(Singleton): # pylint: disable=too-few-public-methods
162+
class ModbusStatus: # pylint: disable=too-few-public-methods
160163
"""These represent various status codes in the modbus protocol.
161164
162165
.. attribute:: Waiting
@@ -193,8 +196,12 @@ class ModbusStatus(Singleton): # pylint: disable=too-few-public-methods
193196
SlaveOn = 0xFF
194197
SlaveOff = 0x00
195198

199+
def __init__(self):
200+
"""Prohibit objects."""
201+
raise RuntimeError(INTERNAL_ERROR)
196202

197-
class Endian(Singleton): # pylint: disable=too-few-public-methods
203+
204+
class Endian: # pylint: disable=too-few-public-methods
198205
"""An enumeration representing the various byte endianness.
199206
200207
.. attribute:: Auto
@@ -218,8 +225,12 @@ class Endian(Singleton): # pylint: disable=too-few-public-methods
218225
Big = ">"
219226
Little = "<"
220227

228+
def __init__(self):
229+
"""Prohibit objects."""
230+
raise RuntimeError(INTERNAL_ERROR)
231+
221232

222-
class ModbusPlusOperation(Singleton): # pylint: disable=too-few-public-methods
233+
class ModbusPlusOperation: # pylint: disable=too-few-public-methods
223234
"""Represents the type of modbus plus request.
224235
225236
.. attribute:: GetStatistics
@@ -236,8 +247,12 @@ class ModbusPlusOperation(Singleton): # pylint: disable=too-few-public-methods
236247
GetStatistics = 0x0003
237248
ClearStatistics = 0x0004
238249

250+
def __init__(self):
251+
"""Prohibit objects."""
252+
raise RuntimeError(INTERNAL_ERROR)
239253

240-
class DeviceInformation(Singleton): # pylint: disable=too-few-public-methods
254+
255+
class DeviceInformation: # pylint: disable=too-few-public-methods
241256
"""Represents what type of device information to read.
242257
243258
.. attribute:: Basic
@@ -269,8 +284,12 @@ class DeviceInformation(Singleton): # pylint: disable=too-few-public-methods
269284
Extended = 0x03
270285
Specific = 0x04
271286

287+
def __init__(self):
288+
"""Prohibit objects."""
289+
raise RuntimeError(INTERNAL_ERROR)
290+
272291

273-
class MoreData(Singleton): # pylint: disable=too-few-public-methods
292+
class MoreData: # pylint: disable=too-few-public-methods
274293
"""Represents the more follows condition.
275294
276295
.. attribute:: Nothing
@@ -285,6 +304,10 @@ class MoreData(Singleton): # pylint: disable=too-few-public-methods
285304
Nothing = 0x00
286305
KeepReading = 0xFF
287306

307+
def __init__(self):
308+
"""Prohibit objects."""
309+
raise RuntimeError(INTERNAL_ERROR)
310+
288311

289312
# ---------------------------------------------------------------------------#
290313
# Exported Identifiers

pymodbus/pdu.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@
44

55
from pymodbus.constants import Defaults
66
from pymodbus.exceptions import NotImplementedException
7-
from pymodbus.interfaces import Singleton
87
from pymodbus.logging import Log
98
from pymodbus.utilities import rtuFrameSize
109

@@ -145,7 +144,7 @@ def isError(self):
145144
# --------------------------------------------------------------------------- #
146145
# Exception PDUs
147146
# --------------------------------------------------------------------------- #
148-
class ModbusExceptions(Singleton): # pylint: disable=too-few-public-methods
147+
class ModbusExceptions: # pylint: disable=too-few-public-methods
149148
"""An enumeration of the valid modbus exceptions."""
150149

151150
IllegalFunction = 0x01

0 commit comments

Comments
 (0)