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

LeanderCS / flask-inputfilter / #405

30 Jun 2025 05:23PM UTC coverage: 92.131% (-1.3%) from 93.409%
#405

push

coveralls-python

web-flow
Merge pull request #57 from LeanderCS/optimize

Optimize InputFilter

304 of 336 new or added lines in 71 files covered. (90.48%)

36 existing lines in 3 files now uncovered.

1885 of 2046 relevant lines covered (92.13%)

0.92 hits per line

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

82.35
/flask_inputfilter/validators/is_instance_validator.py
1
from __future__ import annotations
1✔
2

3
import warnings
1✔
4
from typing import Any, Optional, Type
1✔
5

6
from flask_inputfilter.exceptions import ValidationError
1✔
7
from flask_inputfilter.validators import BaseValidator
1✔
8

9

10
class IsInstanceValidator(BaseValidator):
1✔
11
    """
12
    Validates that the provided value is an instance of a specified class.
13

14
    **Parameters:**
15

16
    - **classType** (*Type[Any]*): The class against which the value is
17
        validated.
18
    - **error_message** (*Optional[str]*): Custom error message if the
19
        validation fails.
20

21
    **Expected Behavior:**
22

23
    Raises a ``ValidationError`` if the input is not an instance of the
24
    specified class.
25

26
    **Example Usage:**
27

28
    .. code-block:: python
29

30
        class MyClass:
31
            pass
32

33
        class InstanceInputFilter(InputFilter):
34
            def __init__(self):
35
                super().__init__()
36
                self.add('object', validators=[
37
                    IsInstanceValidator(classType=MyClass)
38
                ])
39
    """
40

41
    __slots__ = ("class_type", "error_message")
1✔
42

43
    def __init__(
1✔
44
        self,
45
        class_type: Type[Any],
46
        error_message: Optional[str] = None,
47
        classType: Type[Any] = None,
48
    ) -> None:
49
        if classType is not None:
1✔
NEW
50
            warnings.warn(
×
51
                "Parameter 'classType' is deprecated, use 'class_type' "
52
                "instead",
53
                DeprecationWarning,
54
                stacklevel=2,
55
            )
NEW
56
            if class_type is None:
×
NEW
57
                class_type = classType
×
58

59
        self.class_type = class_type
1✔
60
        self.error_message = error_message
1✔
61

62
    def validate(self, value: Any) -> None:
1✔
63
        if not isinstance(value, self.class_type):
1✔
64
            raise ValidationError(
1✔
65
                self.error_message
66
                or f"Value '{value}' is not an instance "
67
                f"of '{self.class_type}'."
68
            )
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