Skip to content

Commit

Permalink
Fix Predicate issue in v2.9.0 (#10321)
Browse files Browse the repository at this point in the history
  • Loading branch information
sydney-runkle committed Sep 9, 2024
1 parent ed92d0a commit 07cbe50
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
2 changes: 2 additions & 0 deletions pydantic/_internal/_known_annotated_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -319,6 +319,8 @@ def val_func(v: Any) -> Any:
f'Not of {predicate_name} failed', # type: ignore # noqa: B023
)

return v

schema = cs.no_info_after_validator_function(val_func, schema)
else:
# ignore any other unknown metadata
Expand Down
6 changes: 6 additions & 0 deletions tests/test_annotated.py
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,12 @@ def test_validate_float_inf_nan_python() -> None:
]


def test_predicate_success_python() -> None:
ta = TypeAdapter(Annotated[int, Predicate(lambda x: x > 0)])

assert ta.validate_python(1) == 1


def test_predicate_error_python() -> None:
ta = TypeAdapter(Annotated[int, Predicate(lambda x: x > 0)])

Expand Down

0 comments on commit 07cbe50

Please sign in to comment.