-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validator examples: behavior does not match what is shown in comments #90
Comments
In the case of @pred_to_validator("Number must be greater than 0", complement=True)
def _is_positive_num(v: Union[int, float]) -> bool:
return v > 0 |
In the case of spec = ValidatorSpec("_is_positive_int", _is_positive_int) Results in the expected behavior. From # dataspec/base.py
def make_spec(..., *preds: SpecPredicate, ...) -> Spec:
...
try:
pred = preds[0]
except IndexError:
raise TypeError("Expected some spec predicate")
...
elif callable(pred):
try:
sig: Optional[inspect.Signature] = inspect.signature(pred)
except (TypeError, ValueError):
# Some builtins may not be inspectable
sig = None
if (
sig is not None and sig.return_annotation is Iterator[ErrorDetails]
) or getattr(pred, "is_validator_fn", False):
return ValidatorSpec(
tag or pred.__name__, cast(ValidatorFn, pred), conformer=conformer
)
else:
return PredicateSpec(
tag or pred.__name__, cast(PredicateFn, pred), conformer=conformer
)
... The example return annotation is Thus, def _is_positive_int(v: Any) -> Iterator[ErrorDetails]:
if not isinstance(v, int):
yield ErrorDetails(
message="Value must be an integer", pred=_is_positive_int, value=v
)
elif v < 1:
yield ErrorDetails(
message="Number must be greater than 0", pred=_is_positive_int, value=v
)
|
Steps to reproduce
spec
methods._is_positive_int
Setup
Expected behavior
Actual behavior
_is_positive_num()
Setup
Expected behavior
Actual behavior
The behavior of
_is_positive_num
appears to be inverted.System configuration
Python version: 3.10.11
Dataspec version: 0.3.2
I'm not yet sure why this happens, as the validation function definitions seem correct.
The text was updated successfully, but these errors were encountered: