• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

LeanderCS / flask-inputfilter / #388

24 May 2025 12:59PM UTC coverage: 93.409% (-0.2%) from 93.644%
#388

Pull #56

coveralls-python

LeanderCS
48 | Remove typing_extensions dep
Pull Request #56: 48 | Update ArrayElementValidator and IsDataclassValidator

67 of 76 new or added lines in 4 files covered. (88.16%)

81 existing lines in 14 files now uncovered.

1885 of 2018 relevant lines covered (93.41%)

0.93 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

95.65
/flask_inputfilter/filters/array_element_filter.py
1
from __future__ import annotations
1✔
2

3
from typing import Any, List, Optional, Union
1✔
4

5
from flask_inputfilter.filters.base_filter import BaseFilter
1✔
6

7

8
class ArrayElementFilter(BaseFilter):
1✔
9
    """
10
    Filters each element in an array by applying one or more `BaseFilter`
11

12
    **Parameters:**
13

14
    - **element_filter** (*BaseFilter* | *list[BaseFilter]*): A filter or a list of filters to apply to each element in the array.
15

16
    **Expected Behavior:**
17

18
    Validates that the input is a list and applies the specified filter(s) to each element. If any element does not conform to the expected structure, a `ValueError` is raised.
19

20
    **Example Usage:**
21

22
    .. code-block:: python
23

24
        class TagInputFilter(InputFilter):
25
            def __init__(self):
26
                super().__init__()
27

28
                self.add('tags', validators=[
29
                    ArrayElementValidator(element_filter=IsStringValidator())
30
                ])
31
    """
32

33
    __slots__ = ("element_filter",)
1✔
34

35
    def __init__(
1✔
36
        self,
37
        element_filter: Union[BaseFilter, List[BaseFilter]],
38
        error_message: Optional[str] = None,
39
    ) -> None:
40
        self.element_filter = element_filter
1✔
41
        self.error_message = error_message
1✔
42

43
    def apply(self, value: Any) -> List[Any]:
1✔
44
        if not isinstance(value, list):
1✔
45
            return value
1✔
46

47
        result = []
1✔
48
        for element in value:
1✔
49
            if isinstance(self.element_filter, BaseFilter):
1✔
50
                result.append(self.element_filter.apply(element))
1✔
51
                continue
1✔
52

53
            elif isinstance(self.element_filter, list) and all(
1✔
54
                isinstance(v, BaseFilter) for v in self.element_filter
55
            ):
56
                for filter_instance in self.element_filter:
1✔
57
                    element = filter_instance.apply(element)
1✔
58
                result.append(element)
1✔
59
                continue
1✔
60

NEW
61
            result.append(element)
×
62
        return result
1✔
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc