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

1"""Module providing the In() sur-Class""" 

2from .generic import GenericType 

3from .error import Error, ErrorType 

4 

5 

6class In(GenericType): 

7 """ 

8 A kind of "one of" 

9 """ 

10 

11 def __init__(self, models: list, **kwargs): 

12 """ 

13 available arguments 

14 

15 """ 

16 self._models = models 

17 GenericType.__init__(self, **kwargs) 

18 

19 def check(self, value): 

20 """ 

21 check if complain to model or return a error string 

22 """ 

23 

24 for model in self._models: 

25 if model is None: 

26 continue 

27 

28 # Look for the good type 

29 try: 

30 if value is not None: 

31 model.check_type(value) 

32 except Error: 

33 continue 

34 

35 # check if OK to the model 

36 return model.check(value) 

37 

38 raise Error(ErrorType.WRONGTYPE, "Match no model", self.path_name())