Coverage for stricto/in_type.py: 100%
17 statements
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-08 22:10 +0100
« prev ^ index » next coverage.py v7.4.1, created at 2024-02-08 22:10 +0100
1"""Module providing the In() sur-Class"""
2from .generic import GenericType
3from .error import Error, ErrorType
6class In(GenericType):
7 """
8 A kind of "one of"
9 """
11 def __init__(self, models: list, **kwargs):
12 """
13 available arguments
15 """
16 self._models = models
17 GenericType.__init__(self, **kwargs)
19 def check(self, value):
20 """
21 check if complain to model or return a error string
22 """
24 for model in self._models:
25 if model is None:
26 continue
28 # Look for the good type
29 try:
30 if value is not None:
31 model.check_type(value)
32 except Error:
33 continue
35 # check if OK to the model
36 return model.check(value)
38 raise Error(ErrorType.WRONGTYPE, "Match no model", self.path_name())