@@ -67,13 +67,16 @@ class _Numerical(DataType[T_Numerical]):
6767 min_alarm : T_Numerical | None = None
6868 max_alarm : T_Numerical | None = None
6969
70- def validate (self , value : T_Numerical ) -> T_Numerical :
71- super ().validate (value )
72- if self .min is not None and value < self .min :
73- raise ValueError (f"Value { value } is less than minimum { self .min } " )
74- if self .max is not None and value > self .max :
75- raise ValueError (f"Value { value } is greater than maximum { self .max } " )
76- return value
70+ def validate (self , value : Any ) -> T_Numerical :
71+ _value = super ().validate (value )
72+
73+ if self .min is not None and _value < self .min :
74+ raise ValueError (f"Value { _value } is less than minimum { self .min } " )
75+
76+ if self .max is not None and _value > self .max :
77+ raise ValueError (f"Value { _value } is greater than maximum { self .max } " )
78+
79+ return _value
7780
7881 @property
7982 def initial_value (self ) -> T_Numerical :
@@ -99,11 +102,13 @@ class Float(_Numerical[float]):
99102 def dtype (self ) -> type [float ]:
100103 return float
101104
102- def validate (self , value : float ) -> float :
103- super ().validate (value )
105+ def validate (self , value : Any ) -> float :
106+ _value = super ().validate (value )
107+
104108 if self .prec is not None :
105- value = round (value , self .prec )
106- return value
109+ _value = round (_value , self .prec )
110+
111+ return _value
107112
108113
109114@dataclass (frozen = True )
@@ -177,21 +182,24 @@ def initial_value(self) -> np.ndarray:
177182 return np .zeros (self .shape , dtype = self .array_dtype )
178183
179184 def validate (self , value : np .ndarray ) -> np .ndarray :
180- super ().validate (value )
181- if self .array_dtype != value .dtype :
185+ _value = super ().validate (value )
186+
187+ if self .array_dtype != _value .dtype :
182188 raise ValueError (
183- f"Value dtype { value .dtype } is not the same as the array dtype "
189+ f"Value dtype { _value .dtype } is not the same as the array dtype "
184190 f"{ self .array_dtype } "
185191 )
186- if len (self .shape ) != len (value .shape ) or any (
192+
193+ if len (self .shape ) != len (_value .shape ) or any (
187194 shape1 > shape2
188- for shape1 , shape2 in zip (value .shape , self .shape , strict = True )
195+ for shape1 , shape2 in zip (_value .shape , self .shape , strict = True )
189196 ):
190197 raise ValueError (
191- f"Value shape { value .shape } exceeeds the shape maximum shape "
198+ f"Value shape { _value .shape } exceeeds the shape maximum shape "
192199 f"{ self .shape } "
193200 )
194- return value
201+
202+ return _value
195203
196204
197205@dataclass (frozen = True )
@@ -207,12 +215,13 @@ def dtype(self) -> type[np.ndarray]:
207215 def initial_value (self ) -> np .ndarray :
208216 return np .array ([], dtype = self .structured_dtype )
209217
210- def validate (self , value : np . ndarray ) -> np .ndarray :
211- super ().validate (value )
218+ def validate (self , value : Any ) -> np .ndarray :
219+ _value = super ().validate (value )
212220
213- if self .structured_dtype != value .dtype :
221+ if self .structured_dtype != _value .dtype :
214222 raise ValueError (
215- f"Value dtype { value .dtype .descr } is not the same as the structured "
223+ f"Value dtype { _value .dtype .descr } is not the same as the structured "
216224 f"dtype { self .structured_dtype } "
217225 )
218- return value
226+
227+ return _value
0 commit comments