We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
Predicate
v2.9.0
1 parent ed92d0a commit 07cbe50Copy full SHA for 07cbe50
pydantic/_internal/_known_annotated_metadata.py
@@ -319,6 +319,8 @@ def val_func(v: Any) -> Any:
319
f'Not of {predicate_name} failed', # type: ignore # noqa: B023
320
)
321
322
+ return v
323
+
324
schema = cs.no_info_after_validator_function(val_func, schema)
325
else:
326
# ignore any other unknown metadata
tests/test_annotated.py
@@ -385,6 +385,12 @@ def test_validate_float_inf_nan_python() -> None:
385
]
386
387
388
+def test_predicate_success_python() -> None:
389
+ ta = TypeAdapter(Annotated[int, Predicate(lambda x: x > 0)])
390
391
+ assert ta.validate_python(1) == 1
392
393
394
def test_predicate_error_python() -> None:
395
ta = TypeAdapter(Annotated[int, Predicate(lambda x: x > 0)])
396
0 commit comments