Skip to content

Commit 07cbe50

Browse files
committed
Fix Predicate issue in v2.9.0 (#10321)
1 parent ed92d0a commit 07cbe50

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

Diff for: pydantic/_internal/_known_annotated_metadata.py

+2
Original file line numberDiff line numberDiff line change
@@ -319,6 +319,8 @@ def val_func(v: Any) -> Any:
319319
f'Not of {predicate_name} failed', # type: ignore # noqa: B023
320320
)
321321

322+
return v
323+
322324
schema = cs.no_info_after_validator_function(val_func, schema)
323325
else:
324326
# ignore any other unknown metadata

Diff for: tests/test_annotated.py

+6
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,12 @@ def test_validate_float_inf_nan_python() -> None:
385385
]
386386

387387

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+
388394
def test_predicate_error_python() -> None:
389395
ta = TypeAdapter(Annotated[int, Predicate(lambda x: x > 0)])
390396

0 commit comments

Comments
 (0)