Coverage for stricto/float.py: 100%
18 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-08 17:22 +0100
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-08 17:22 +0100
1"""Module providing the Float() Class"""
2from .generic import GenericType
3from .error import Error, ErrorType
6class Float(GenericType):
7 """
8 A Float type
9 """
11 def __init__(self, **kwargs):
12 """
13 available arguments
15 min : minimal value
16 max : maximal value
18 """
19 GenericType.__init__(self, **kwargs)
20 self._min = kwargs.pop("min", kwargs.pop("minimum", None))
21 self._max = kwargs.pop("max", kwargs.pop("maximum", None))
23 def check_type(self, value):
24 if isinstance(value, (float, Float)):
25 return True
26 raise Error(ErrorType.WRONGTYPE, "Must be a float", self.path_name())
28 def check_constraints(self, value):
30 GenericType.check_constraints(self, value)
32 if self._min is not None and value < self._min:
33 raise Error(ErrorType.LENGTH, "Must be above Minimal", self.path_name())
34 if self._max is not None and value > self._max:
35 raise Error(ErrorType.LENGTH, "Must be below Maximal", self.path_name())
36 return True