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

NeuralEnsemble / elephant / 19269999990

11 Nov 2025 03:13PM UTC coverage: 88.283% (+0.02%) from 88.262%
19269999990

Pull #678

github

web-flow
Merge 1f58b1207 into 539258334
Pull Request #678: Feature/partial First Pydantic Models for parameter validation

542 of 587 new or added lines in 9 files covered. (92.33%)

22 existing lines in 4 files now uncovered.

7241 of 8202 relevant lines covered (88.28%)

5.28 hits per line

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

91.3
/elephant/schemas/function_validator.py
1
from functools import wraps
6✔
2
from inspect import signature
6✔
3
from pydantic import BaseModel
6✔
4

5
skip_validation = False
6✔
6

7
def validate_with(model_class: type[BaseModel]):
6✔
8
    """
9
    A decorator that validates the inputs of a function using a Pydantic model.
10
    Works for both positional and keyword arguments.
11
    """
12
    def decorator(func):
6✔
13
        sig = signature(func)
6✔
14

15
        @wraps(func)
6✔
16
        def wrapper(*args, **kwargs):
6✔
17

18
            if kwargs.pop("not_validate", False) or skip_validation:
6✔
19
            # skip validation, call inner function directly
20
                return func(*args, **kwargs)
6✔
21

22
            # Bind args & kwargs to function parameters
23
            bound = sig.bind_partial(*args, **kwargs)
6✔
24
            bound.apply_defaults()
6✔
25
            data = bound.arguments
6✔
26

27
            # Validate using Pydantic
28
            model_class(**data)
6✔
29

30
            # Call function
31
            return func(*args, **kwargs)
6✔
32
        wrapper._is_validate_with = True
6✔
33
        return wrapper
6✔
34
    return decorator
6✔
35

36
def activate_validation():
6✔
NEW
37
    skip_validation = False
×
38

39
def deactivate_validation():
6✔
NEW
40
    skip_validation = True
×
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