Skip to content

Commit 5003c2d

Browse files
authored
Add more type hints to datastore (#2028)
1 parent 3ed28ce commit 5003c2d

File tree

1 file changed

+14
-11
lines changed

1 file changed

+14
-11
lines changed

pymodbus/datastore/store.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,16 @@
4545
based on their preference.
4646
"""
4747
# pylint: disable=missing-type-doc
48-
from pymodbus.exceptions import NotImplementedException, ParameterException
48+
from abc import ABC, abstractmethod
49+
from typing import Iterable
50+
51+
from pymodbus.exceptions import ParameterException
4952

5053

5154
# ---------------------------------------------------------------------------#
5255
# Datablock Storage
5356
# ---------------------------------------------------------------------------#
54-
class BaseModbusDataBlock:
57+
class BaseModbusDataBlock(ABC):
5558
"""Base class for a modbus datastore.
5659
5760
Derived classes must create the following fields:
@@ -83,32 +86,32 @@ def reset(self):
8386
self.default_value
8487
] * len(self.values)
8588

86-
def validate(self, address, count=1):
89+
@abstractmethod
90+
def validate(self, address:int, count=1) -> bool:
8791
"""Check to see if the request is in range.
8892
8993
:param address: The starting address
9094
:param count: The number of values to test for
91-
:raises NotImplementedException:
95+
:raises TypeError:
9296
"""
93-
raise NotImplementedException("Datastore Address Check")
9497

95-
def getValues(self, address, count=1):
98+
@abstractmethod
99+
def getValues(self, address:int, count=1) -> Iterable:
96100
"""Return the requested values from the datastore.
97101
98102
:param address: The starting address
99103
:param count: The number of values to retrieve
100-
:raises NotImplementedException:
104+
:raises TypeError:
101105
"""
102-
raise NotImplementedException("Datastore Value Retrieve")
103106

104-
def setValues(self, address, values):
107+
@abstractmethod
108+
def setValues(self, address:int, values) -> None:
105109
"""Return the requested values from the datastore.
106110
107111
:param address: The starting address
108112
:param values: The values to store
109-
:raises NotImplementedException:
113+
:raises TypeError:
110114
"""
111-
raise NotImplementedException("Datastore Value Retrieve")
112115

113116
def __str__(self):
114117
"""Build a representation of the datastore.

0 commit comments

Comments
 (0)