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

LeanderCS / flask-inputfilter / #415

01 Jul 2025 11:14PM UTC coverage: 95.53% (-0.3%) from 95.792%
#415

push

coveralls-python

LeanderCS
Switch to ruff

69 of 81 new or added lines in 42 files covered. (85.19%)

5 existing lines in 3 files now uncovered.

1838 of 1924 relevant lines covered (95.53%)

0.96 hits per line

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

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

3
from typing import Any, Union
1✔
4

5
from flask_inputfilter.models 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
15
      list of filters to apply to each element in the array.
16

17
    **Expected Behavior:**
18

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

23
    **Example Usage:**
24

25
    .. code-block:: python
26

27
        class TagInputFilter(InputFilter):
28
            def __init__(self):
29
                super().__init__()
30

31
                self.add('tags', validators=[
32
                    ArrayElementValidator(element_filter=IsStringValidator())
33
                ])
34
    """
35

36
    __slots__ = ("element_filter",)
1✔
37

38
    def __init__(
1✔
39
        self,
40
        element_filter: Union[BaseFilter, list[BaseFilter]],
41
    ) -> None:
42
        self.element_filter = element_filter
1✔
43

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

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

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

UNCOV
62
            result.append(element)
×
63
        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