Backtestspydanticrun-20261005-183002#13507
Experimental pipeline: every constraint chained after ge/lt/le is dropped from the JSON schema
Our patch was judged better than the merged fix.
In this judgment, Patch B = our agent, Patch A = the merged fix.
Both patches fix the reported root cause: they stop wrapping the schema in a `function-after` validator once the native `ge`/`lt`/`le`/`multiple_of` field has been set. That lets later constraints in the chain reach the JSON schema. The difference is what happens when the same constraint appears twice. **Patch A introduces a validation regression.** It writes the native field unconditionally and drops the fallback check, so a repeated constraint overwrites the earlier one. `validate_as(int).ge(5).ge(1)` ends with `ge=1` and accepts 3. `multiple_of(2).multiple_of(3)` ends with `multiple_of=3` and accepts 3. Before the patch, the earlier bound survived inside the function wrapper, so validation was correct; Patch A breaks that. The issue specifically stresses that validation is currently correct, so this is a real step backward. Patch A also removes the type-match guards (int bound on int schema, float on float, Decimal on decimal). It relies on its own comment that pydantic-core will cast a mismatched bound, such as `gt=1.5` on an int schema. That is unverified and riskier than keeping the guarded fallback. It does add tests for mixed-type bounds and the chain cases from the issue, but nothing for repeated constraints. **Patch B avoids that regression.** It follows the `native_constraint_applied` shape the issue proposes, consistently across Gt/Ge/Lt/Le/MultipleOf. It keeps the type-match guards, so mismatched bounds still go through the fallback validator. When a bound is repeated it merges them, keeping the stricter value via `max`/`min`. For a second `multiple_of`, which can't be merged, it keeps the first native and adds a function check for the second. Patch B also extends the same treatment to `Len` and adjusts `str_strip` so a length check placed before stripping still sees the unstripped value. That goes beyond the issue, but it is coherent, needed for the `Len` change to be correct, and tested. Patch B's tests check both the JSON schema and validation for every scenario in the issue, plus float and Decimal variants. They also cover repeated constraints keeping the strictest bound, len-then-strip ordering, and the Gt fallback on a type mismatch. On correctness, which is the most important criterion, Patch B is clearly better.
The judge saw only the two patches, labelled A and B in random order, with issue links and version numbers removed. The reasoning above is shown verbatim.
Solve
9m 23s
Wall-clock time in the container
Full test suite
No new failures
12,294 passed · 501 skipped · 12,795 total
Contamination audit
Clean
No sign the agent saw the real fix
Patch size
263vs 112 merged
Changed lines, ours vs merged
The issue
View on GitHubInitial Checks
- I confirm that I'm using Pydantic V2
Description
In the experimental pipeline API, chaining constraints silently drops every bound after the first from the generated JSON schema. Validation stays correct - only the published schema is wrong, which makes it easy to miss.
All bounds below are non-zero, so this is not #13450 (falsy zero bounds in Interval). Observed identically on released 2.13.4 and on main (2.14.0a1).
| expression | JSON schema | validation |
|---|---|---|
validate_as(int).ge(1).le(100) | {"minimum": 1, "type": "integer"} | 0 reject, 50 accept, 200 reject |
validate_as(int).le(100).ge(1) | {"maximum": 100, "type": "integer"} | 0 reject, 50 accept, 200 reject |
validate_as(int).constrain(Interval(ge=1, le=100)) | {"minimum": 1, "type": "integer"} | 0 reject, 50 accept, 200 reject |
validate_as(int).ge(1).le(100).multiple_of(5) | {"minimum": 1, "type": "integer"} | correct |
validate_as(int).gt(1).lt(100) (control) | {"exclusiveMinimum": 1, "exclusiveMaximum": 100, ...} | correct |
Annotated[int, Ge(1), Le(100)] (control) | {"minimum": 1, "maximum": 100, ...} | correct |
So .ge(1).le(100).multiple_of(5) publishes a schema advertising any integer >= 1, while the validator rejects 200 and 52. For FastAPI that means the OpenAPI component and every generated client disagree with the server.
Cause
In _apply_constraint(), the Ge, Lt and Le branches apply their fallback function validator unconditionally - including when the native core-schema field was just set:
elif isinstance(constraint, annotated_types.Ge):
ge = constraint.ge
if s and s['type'] in {'int', 'float', 'decimal'}:
s = s.copy()
if s['type'] == 'int' and isinstance(ge, int):
s['ge'] = ge # native constraint applied...
...
def check_ge(v: Any) -> bool:
return v >= ge
s = _check_func(check_ge, f'>= {ge}', s) # ...and then wrapped anyway
_check_func wraps the schema in function-after. The next constraint in the chain sees s['type'] == 'function-after', which is not in {'int', 'float', 'decimal'}, so it cannot set its own native field and survives only inside an opaque callable that JSON-schema generation cannot read. Core schema for .ge(1).le(100):
{'type': 'function-after',
'function': ..., # <- le(100) lives in here, invisible to the schema
'schema': {'type': 'function-after',
'function': ..., # <- redundant ge check
'schema': {'type': 'int', 'ge': 1}}}
Gt is the control that works, and only by accident: its fallback sits in an else:, so nothing is wrapped when the native constraint applies.
Relationship to the open PRs in this function
Two in-flight PRs each fix one branch of this, for unrelated reasons, and between them they leave Ge, Lt and Le untouched:
- #13473 adds a
native_constraint_appliedflag toMultipleOfto avoid a float parity problem. Same shape as the fix needed here. - #13446 restructures
Gtso the fallback lands inside the numeric branch.
Worth flagging on the second one: #13446's description argues that Gt is uniquely broken and holds up Ge/Lt/Le/MultipleOf as the correct model, because they "always apply" the check and so enforce the bound on a type mismatch. That is true of validation, but always applying it is exactly what destroys the schema. Gt is uniquely broken for validation; the other four are broken for schema. Whichever way this is fixed, it probably wants to be one symmetric change across all five branches rather than three separate patches.
Example Code
from typing import Annotated
from pydantic import TypeAdapter
from pydantic.experimental.pipeline import validate_as
ta = TypeAdapter(Annotated[int, validate_as(int).ge(1).le(100)])
print(ta.json_schema()) # {'minimum': 1, 'type': 'integer'} <- no maximum
ta.validate_python(200) # ValidationError, as it should be
# control: the same constraints without the pipeline
import annotated_types
print(TypeAdapter(Annotated[int, annotated_types.Ge(1), annotated_types.Le(100)]).json_schema())
# {'maximum': 100, 'minimum': 1, 'type': 'integer'}
Python, Pydantic & OS Version
pydantic version: 2.13.4
pydantic-core version: 2.46.4
pydantic-core build: profile=release pgo=false
python version: 3.11.15 (main, Mar 3 2026, 09:26:23) [GCC 13.3.0]
platform: Linux-6.18.5-x86_64-with-glibc2.39
related packages: typing_extensions-4.16.0
commit: unknown
I have a PR ready that applies the native_constraint_applied shape from #13473 to Ge/Lt/Le, with regression tests that fail without it. Happy to open it, or to fold it into one of the existing PRs if you'd rather land a single change.
The two patches
pydantic/experimental/pipeline.pyindex b9668517..25ac7320 100644@@ -464,7 +464,8 @@ def _apply_transform( return cs.no_info_plain_validator_function(func) if s['type'] == 'str':- if func is str.strip:+ # core strips before checking length, so a length constraint applied earlier in the pipeline must not see it+ if func is str.strip and 'min_length' not in s and 'max_length' not in s: s = s.copy() s['strip_whitespace'] = True return s@@ -486,15 +487,21 @@ def _apply_constraint( # noqa: C901 """Apply a single constraint to a schema.""" if isinstance(constraint, annotated_types.Gt): gt = constraint.gt+ # Only fall back to a function validator if the native constraint could not be applied:+ # wrapping the schema would otherwise hide it (and any later constraint) from JSON schema generation.+ native_constraint_applied = False if s and s['type'] in {'int', 'float', 'decimal'}:- s = s.copy()- if s['type'] == 'int' and isinstance(gt, int):- s['gt'] = gt- elif s['type'] == 'float' and isinstance(gt, float):- s['gt'] = gt- elif s['type'] == 'decimal' and isinstance(gt, Decimal):- s['gt'] = gt- else:+ if (+ (s['type'] == 'int' and isinstance(gt, int))+ or (s['type'] == 'float' and isinstance(gt, float))+ or (s['type'] == 'decimal' and isinstance(gt, Decimal))+ ):+ s = s.copy()+ # merge with an existing bound rather than overwriting it, so the stricter one wins+ s['gt'] = max(s['gt'], gt) if 'gt' in s else gt+ native_constraint_applied = True++ if not native_constraint_applied: def check_gt(v: Any) -> bool: return v > gt@@ -502,49 +509,70 @@ def _apply_constraint( # noqa: C901 s = _check_func(check_gt, f'> {gt}', s) elif isinstance(constraint, annotated_types.Ge): ge = constraint.ge+ # Only fall back to a function validator if the native constraint could not be applied:+ # wrapping the schema would otherwise hide it (and any later constraint) from JSON schema generation.+ native_constraint_applied = False if s and s['type'] in {'int', 'float', 'decimal'}:- s = s.copy()- if s['type'] == 'int' and isinstance(ge, int):- s['ge'] = ge- elif s['type'] == 'float' and isinstance(ge, float):- s['ge'] = ge- elif s['type'] == 'decimal' and isinstance(ge, Decimal):- s['ge'] = ge+ if (+ (s['type'] == 'int' and isinstance(ge, int))+ or (s['type'] == 'float' and isinstance(ge, float))+ or (s['type'] == 'decimal' and isinstance(ge, Decimal))+ ):+ s = s.copy()+ # merge with an existing bound rather than overwriting it, so the stricter one wins+ s['ge'] = max(s['ge'], ge) if 'ge' in s else ge+ native_constraint_applied = True++ if not native_constraint_applied: - def check_ge(v: Any) -> bool:- return v >= ge+ def check_ge(v: Any) -> bool:+ return v >= ge - s = _check_func(check_ge, f'>= {ge}', s)+ s = _check_func(check_ge, f'>= {ge}', s) elif isinstance(constraint, annotated_types.Lt): lt = constraint.lt+ # Only fall back to a function validator if the native constraint could not be applied:+ # wrapping the schema would otherwise hide it (and any later constraint) from JSON schema generation.+ native_constraint_applied = False if s and s['type'] in {'int', 'float', 'decimal'}:- s = s.copy()- if s['type'] == 'int' and isinstance(lt, int):- s['lt'] = lt- elif s['type'] == 'float' and isinstance(lt, float):- s['lt'] = lt- elif s['type'] == 'decimal' and isinstance(lt, Decimal):- s['lt'] = lt+ if (+ (s['type'] == 'int' and isinstance(lt, int))+ or (s['type'] == 'float' and isinstance(lt, float))+ or (s['type'] == 'decimal' and isinstance(lt, Decimal))+ ):+ s = s.copy()+ # merge with an existing bound rather than overwriting it, so the stricter one wins+ s['lt'] = min(s['lt'], lt) if 'lt' in s else lt+ native_constraint_applied = True++ if not native_constraint_applied: - def check_lt(v: Any) -> bool:- return v < lt+ def check_lt(v: Any) -> bool:+ return v < lt - s = _check_func(check_lt, f'< {lt}', s)+ s = _check_func(check_lt, f'< {lt}', s) elif isinstance(constraint, annotated_types.Le): le = constraint.le+ # Only fall back to a function validator if the native constraint could not be applied:+ # wrapping the schema would otherwise hide it (and any later constraint) from JSON schema generation.+ native_constraint_applied = False if s and s['type'] in {'int', 'float', 'decimal'}:- s = s.copy()- if s['type'] == 'int' and isinstance(le, int):- s['le'] = le- elif s['type'] == 'float' and isinstance(le, float):- s['le'] = le- elif s['type'] == 'decimal' and isinstance(le, Decimal):- s['le'] = le+ if (+ (s['type'] == 'int' and isinstance(le, int))+ or (s['type'] == 'float' and isinstance(le, float))+ or (s['type'] == 'decimal' and isinstance(le, Decimal))+ ):+ s = s.copy()+ # merge with an existing bound rather than overwriting it, so the stricter one wins+ s['le'] = min(s['le'], le) if 'le' in s else le+ native_constraint_applied = True++ if not native_constraint_applied: - def check_le(v: Any) -> bool:- return v <= le+ def check_le(v: Any) -> bool:+ return v <= le - s = _check_func(check_le, f'<= {le}', s)+ s = _check_func(check_le, f'<= {le}', s) elif isinstance(constraint, annotated_types.Len): min_len = constraint.min_length max_len = constraint.max_length@@ -559,32 +587,39 @@ def _apply_constraint( # noqa: C901 or s['type'] == 'frozenset' ) s = s.copy()+ # merge with existing bounds rather than overwriting them, so the stricter ones win if min_len != 0:- s['min_length'] = min_len+ s['min_length'] = max(s['min_length'], min_len) if 'min_length' in s else min_len if max_len is not None:- s['max_length'] = max_len+ s['max_length'] = min(s['max_length'], max_len) if 'max_length' in s else max_len+ else: - def check_len(v: Any) -> bool:- if max_len is not None:- return (min_len <= len(v)) and (len(v) <= max_len)- return min_len <= len(v)+ def check_len(v: Any) -> bool:+ if max_len is not None:+ return (min_len <= len(v)) and (len(v) <= max_len)+ return min_len <= len(v) - s = _check_func(check_len, f'length >= {min_len} and length <= {max_len}', s)+ s = _check_func(check_len, f'length >= {min_len} and length <= {max_len}', s) elif isinstance(constraint, annotated_types.MultipleOf): multiple_of = constraint.multiple_of+ native_constraint_applied = False if s and s['type'] in {'int', 'float', 'decimal'}:- s = s.copy()- if s['type'] == 'int' and isinstance(multiple_of, int):- s['multiple_of'] = multiple_of- elif s['type'] == 'float' and isinstance(multiple_of, float):- s['multiple_of'] = multiple_of- elif s['type'] == 'decimal' and isinstance(multiple_of, Decimal):+ if (+ (s['type'] == 'int' and isinstance(multiple_of, int))+ or (s['type'] == 'float' and isinstance(multiple_of, float))+ or (s['type'] == 'decimal' and isinstance(multiple_of, Decimal))+ ) and 'multiple_of' not in s:+ # two divisors can't be merged into a single native value, so only the first one is native+ s = s.copy() s['multiple_of'] = multiple_of+ native_constraint_applied = True++ if not native_constraint_applied: - def check_multiple_of(v: Any) -> bool:- return v % multiple_of == 0+ def check_multiple_of(v: Any) -> bool:+ return v % multiple_of == 0 - s = _check_func(check_multiple_of, f'% {multiple_of} == 0', s)+ s = _check_func(check_multiple_of, f'% {multiple_of} == 0', s) elif isinstance(constraint, annotated_types.Timezone): tz = constraint.tz tests/test_pipeline.pyindex 00e42101..d0c0e3ef 100644@@ -376,6 +376,124 @@ def test_json_schema( assert schema == expected_ser_schema +@pytest.mark.parametrize(+ 'pipeline, expected_schema, valid, invalid',+ [+ (validate_as(int).ge(1).le(100), {'type': 'integer', 'minimum': 1, 'maximum': 100}, [1, 50, 100], [0, 101]),+ (validate_as(int).le(100).ge(1), {'type': 'integer', 'minimum': 1, 'maximum': 100}, [1, 50, 100], [0, 101]),+ (+ validate_as(int).lt(100).gt(1),+ {'type': 'integer', 'exclusiveMinimum': 1, 'exclusiveMaximum': 100},+ [2, 99],+ [1, 100],+ ),+ (+ validate_as(int).constrain(Interval(ge=1, le=100)),+ {'type': 'integer', 'minimum': 1, 'maximum': 100},+ [1, 100],+ [0, 101],+ ),+ (+ validate_as(int).constrain(Interval(gt=1, lt=100)),+ {'type': 'integer', 'exclusiveMinimum': 1, 'exclusiveMaximum': 100},+ [2, 99],+ [1, 100],+ ),+ (+ validate_as(int).ge(1).le(100).multiple_of(5),+ {'type': 'integer', 'minimum': 1, 'maximum': 100, 'multipleOf': 5},+ [5, 100],+ [0, 52, 200],+ ),+ (+ validate_as(int).multiple_of(5).ge(1).le(100),+ {'type': 'integer', 'minimum': 1, 'maximum': 100, 'multipleOf': 5},+ [5, 100],+ [0, 52, 200],+ ),+ (+ validate_as(float).ge(1.0).lt(10.0),+ {'type': 'number', 'minimum': 1.0, 'exclusiveMaximum': 10.0},+ [1.0, 9.5],+ [0.5, 10.0],+ ),+ (+ validate_as(Decimal).gt(Decimal('1')).le(Decimal('10')),+ {+ 'anyOf': [+ {'type': 'number', 'exclusiveMinimum': 1.0, 'maximum': 10.0},+ {'type': 'string', 'pattern': '^(?!^[-+.]*$)[+-]?0*\\d*\\.?\\d*$'},+ ]+ },+ [Decimal('1.5'), Decimal('10')],+ [Decimal('1'), Decimal('10.5')],+ ),+ (+ validate_as(str).str_strip().len(2, 5).str_lower(),+ {'type': 'string', 'minLength': 2, 'maxLength': 5},+ ['ab', 'abcde'],+ ['a', 'abcdef'],+ ),+ (+ validate_as(list[int]).len(1, 3).len(2),+ {'type': 'array', 'items': {'type': 'integer'}, 'minItems': 2, 'maxItems': 3},+ [[1, 2], [1, 2, 3]],+ [[1], [1, 2, 3, 4]],+ ),+ ],+)+def test_chained_constraints_json_schema(+ pipeline: Any, expected_schema: dict[str, Any], valid: list[Any], invalid: list[Any]+) -> None:+ """Every constraint in a chain must reach the JSON schema, not only the first one."""+ ta = TypeAdapter[Any](Annotated[Any, pipeline])+ assert ta.json_schema(mode='validation') == expected_schema++ for v in valid:+ assert ta.validate_python(v) == v+ for v in invalid:+ with pytest.raises(ValidationError):+ ta.validate_python(v)+++@pytest.mark.parametrize(+ 'pipeline, valid, invalid',+ [+ (validate_as(int).ge(5).ge(1), [5], [3]),+ (validate_as(int).gt(5).gt(1), [6], [3]),+ (validate_as(int).le(1).le(5), [1], [3]),+ (validate_as(int).lt(2).lt(9), [1], [3]),+ (validate_as(int).multiple_of(2).multiple_of(3), [6], [2, 3]),+ (validate_as(str).len(2, 3).len(0, 10), ['abc'], ['a', 'abcdefg']),+ (validate_as(list[int]).len(3).len(1), [[1, 2, 3]], [[1, 2]]),+ ],+)+def test_repeated_constraint_keeps_strictest(pipeline: Any, valid: list[Any], invalid: list[Any]) -> None:+ """Repeating a constraint must not let a later, looser bound overwrite an earlier, stricter one."""+ ta = TypeAdapter[Any](Annotated[Any, pipeline])+ for v in valid:+ assert ta.validate_python(v) == v+ for v in invalid:+ with pytest.raises(ValidationError):+ ta.validate_python(v)+++def test_len_then_strip_checks_unstripped_length() -> None:+ """A length constraint placed before `str_strip()` applies to the value before stripping."""+ ta = TypeAdapter[str](Annotated[str, validate_as(str).len(0, 3).str_strip()])+ assert ta.validate_python(' a ') == 'a'+ with pytest.raises(ValidationError):+ ta.validate_python(' ab ')+++def test_gt_fallback_on_bound_type_mismatch() -> None:+ """A bound whose type doesn't match the numeric schema must still be enforced via the fallback validator."""+ ta = TypeAdapter[int](Annotated[int, validate_as(int).gt(1.5)])+ assert ta.validate_python(2) == 2+ with pytest.raises(ValidationError):+ ta.validate_python(1)++ def test_transform_first_step() -> None: """Check that when transform() is used as the first step in a pipeline it run after parsing.""" ta = TypeAdapter[int](Annotated[int, transform(lambda x: x + 1)])
pydantic/experimental/pipeline.pyindex b96685172..806156842 100644@@ -8,7 +8,6 @@ import re from collections import deque from collections.abc import Callable, Container from dataclasses import dataclass-from decimal import Decimal from functools import cached_property, partial from re import Pattern from types import EllipsisType@@ -484,16 +483,13 @@ def _apply_constraint( # noqa: C901 s: cs.CoreSchema | None, constraint: _ConstraintAnnotation ) -> cs.CoreSchema: """Apply a single constraint to a schema."""+ # No casting of the constraints is necessary, as pydantic-core does it+ # when building the validator from the core schema: if isinstance(constraint, annotated_types.Gt): gt = constraint.gt if s and s['type'] in {'int', 'float', 'decimal'}: s = s.copy()- if s['type'] == 'int' and isinstance(gt, int):- s['gt'] = gt- elif s['type'] == 'float' and isinstance(gt, float):- s['gt'] = gt- elif s['type'] == 'decimal' and isinstance(gt, Decimal):- s['gt'] = gt+ s['gt'] = gt # pyright: ignore[reportGeneralTypeIssues] else: def check_gt(v: Any) -> bool:@@ -504,47 +500,35 @@ def _apply_constraint( # noqa: C901 ge = constraint.ge if s and s['type'] in {'int', 'float', 'decimal'}: s = s.copy()- if s['type'] == 'int' and isinstance(ge, int):- s['ge'] = ge- elif s['type'] == 'float' and isinstance(ge, float):- s['ge'] = ge- elif s['type'] == 'decimal' and isinstance(ge, Decimal):- s['ge'] = ge+ s['ge'] = ge # pyright: ignore[reportGeneralTypeIssues]+ else: - def check_ge(v: Any) -> bool:- return v >= ge+ def check_ge(v: Any) -> bool:+ return v >= ge - s = _check_func(check_ge, f'>= {ge}', s)+ s = _check_func(check_ge, f'>= {ge}', s) elif isinstance(constraint, annotated_types.Lt): lt = constraint.lt if s and s['type'] in {'int', 'float', 'decimal'}: s = s.copy()- if s['type'] == 'int' and isinstance(lt, int):- s['lt'] = lt- elif s['type'] == 'float' and isinstance(lt, float):- s['lt'] = lt- elif s['type'] == 'decimal' and isinstance(lt, Decimal):- s['lt'] = lt+ s['lt'] = lt # pyright: ignore[reportGeneralTypeIssues]+ else: - def check_lt(v: Any) -> bool:- return v < lt+ def check_lt(v: Any) -> bool:+ return v < lt - s = _check_func(check_lt, f'< {lt}', s)+ s = _check_func(check_lt, f'< {lt}', s) elif isinstance(constraint, annotated_types.Le): le = constraint.le if s and s['type'] in {'int', 'float', 'decimal'}: s = s.copy()- if s['type'] == 'int' and isinstance(le, int):- s['le'] = le- elif s['type'] == 'float' and isinstance(le, float):- s['le'] = le- elif s['type'] == 'decimal' and isinstance(le, Decimal):- s['le'] = le+ s['le'] = le # pyright: ignore[reportGeneralTypeIssues]+ else: - def check_le(v: Any) -> bool:- return v <= le+ def check_le(v: Any) -> bool:+ return v <= le - s = _check_func(check_le, f'<= {le}', s)+ s = _check_func(check_le, f'<= {le}', s) elif isinstance(constraint, annotated_types.Len): min_len = constraint.min_length max_len = constraint.max_length@@ -574,17 +558,13 @@ def _apply_constraint( # noqa: C901 multiple_of = constraint.multiple_of if s and s['type'] in {'int', 'float', 'decimal'}: s = s.copy()- if s['type'] == 'int' and isinstance(multiple_of, int):- s['multiple_of'] = multiple_of- elif s['type'] == 'float' and isinstance(multiple_of, float):- s['multiple_of'] = multiple_of- elif s['type'] == 'decimal' and isinstance(multiple_of, Decimal):- s['multiple_of'] = multiple_of+ s['multiple_of'] = multiple_of # pyright: ignore[reportGeneralTypeIssues]+ else: - def check_multiple_of(v: Any) -> bool:- return v % multiple_of == 0+ def check_multiple_of(v: Any) -> bool:+ return v % multiple_of == 0 - s = _check_func(check_multiple_of, f'% {multiple_of} == 0', s)+ s = _check_func(check_multiple_of, f'% {multiple_of} == 0', s) elif isinstance(constraint, annotated_types.Timezone): tz = constraint.tz tests/test_pipeline.pyindex 00e421012..7198d4302 100644@@ -34,15 +34,30 @@ def test_parse_str_with_pattern() -> None: (int, validate_as(...).ge(0), [0, 1, 100], [-1, -100]), (float, validate_as(...).ge(0.0), [1.8, 0.0], [-1.0]), (Decimal, validate_as(...).ge(Decimal(0.0)), [Decimal(1), Decimal(0.0)], [Decimal(-1.0)]),+ (float, validate_as(float).ge(0), [1.8, 0.0], [-1.0]),+ (Decimal, validate_as(Decimal).ge(0), [Decimal(1), Decimal(0)], [Decimal(-1)]), # pyright: ignore[reportArgumentType]+ (int, validate_as(int).ge(0.0), [0, 1, 100], [-1, -100]), # pyright: ignore[reportArgumentType]+ # The `transform()` step results in a non-numeric core schema, meaning the constraint+ # is applied as a function check:+ (int, validate_as(int).transform(lambda x: x).ge(0), [0, 1, 100], [-1, -100]), (int, validate_as(...).le(5), [2, 4], [6, 100]), (float, validate_as(...).le(1.0), [0.5, 0.0], [100.0]), (Decimal, validate_as(...).le(Decimal(1.0)), [Decimal(1)], [Decimal(5.0)]),+ (float, validate_as(float).le(1), [0.5, 0.0], [100.0]),+ (Decimal, validate_as(Decimal).le(1), [Decimal(1)], [Decimal(5)]), # pyright: ignore[reportArgumentType]+ (int, validate_as(int).le(5.0), [2, 4], [6, 100]), # pyright: ignore[reportArgumentType] (int, validate_as(...).gt(0), [1, 2, 100], [0, -1]), (float, validate_as(...).gt(0.0), [0.1, 1.8], [0.0, -1.0]), (Decimal, validate_as(...).gt(Decimal(0.0)), [Decimal(1)], [Decimal(0.0), Decimal(-1.0)]),+ (float, validate_as(float).gt(0), [1.0, 2.5], [0.0, -1.0]),+ (Decimal, validate_as(Decimal).gt(0), [Decimal(1)], [Decimal(0), Decimal(-1)]), # pyright: ignore[reportArgumentType]+ (int, validate_as(int).gt(0.0), [1, 2], [0, -3]), # pyright: ignore[reportArgumentType] (int, validate_as(...).lt(5), [2, 4], [5, 6, 100]), (float, validate_as(...).lt(1.0), [0.5, 0.0], [1.0, 100.0]), (Decimal, validate_as(...).lt(Decimal(1.0)), [Decimal(0.5)], [Decimal(1.0), Decimal(5.0)]),+ (float, validate_as(float).lt(1), [0.5, 0.0], [1.0, 100.0]),+ (Decimal, validate_as(Decimal).lt(1), [Decimal('0.5')], [Decimal(1), Decimal(5)]), # pyright: ignore[reportArgumentType]+ (int, validate_as(int).lt(5.0), [2, 4], [5, 6, 100]), # pyright: ignore[reportArgumentType] ], ) def test_ge_le_gt_lt(@@ -61,6 +76,12 @@ def test_ge_le_gt_lt( [ (int, validate_as(int).multiple_of(5), [5, 20, 0], [18, 7]), (float, validate_as(float).multiple_of(2.5), [2.5, 5.0, 7.5], [3.0, 1.1]),+ (float, validate_as(float).multiple_of(2), [2.0, 4.0, 6.0], [3.0, 1.1]),+ (Decimal, validate_as(Decimal).multiple_of(2), [Decimal(2), Decimal(4)], [Decimal(3), Decimal('1.1')]), # pyright: ignore[reportArgumentType]+ (int, validate_as(int).multiple_of(5.0), [5, 20, 0], [18, 7]), # pyright: ignore[reportArgumentType]+ # The `transform()` step results in a non-numeric core schema, meaning the constraint+ # is applied as a function check:+ (int, validate_as(int).transform(lambda x: x).multiple_of(5), [5, 20, 0], [18, 7]), ( Decimal, validate_as(Decimal).multiple_of(Decimal('1.5')),@@ -338,6 +359,31 @@ def test_predicates() -> None: {'type': 'integer', 'exclusiveMinimum': 0, 'exclusiveMaximum': 100}, {'type': 'integer', 'exclusiveMinimum': 0, 'exclusiveMaximum': 100}, ),+ (+ Annotated[int, validate_as(int).ge(1).le(100)],+ {'type': 'integer', 'minimum': 1, 'maximum': 100},+ {'type': 'integer', 'minimum': 1, 'maximum': 100},+ ),+ (+ Annotated[int, validate_as(int).le(100).ge(1)],+ {'type': 'integer', 'minimum': 1, 'maximum': 100},+ {'type': 'integer', 'minimum': 1, 'maximum': 100},+ ),+ (+ Annotated[int, validate_as(int).constrain(Interval(ge=1, le=100))],+ {'type': 'integer', 'minimum': 1, 'maximum': 100},+ {'type': 'integer', 'minimum': 1, 'maximum': 100},+ ),+ (+ Annotated[int, validate_as(int).ge(1).le(100).multiple_of(5)],+ {'type': 'integer', 'minimum': 1, 'maximum': 100, 'multipleOf': 5},+ {'type': 'integer', 'minimum': 1, 'maximum': 100, 'multipleOf': 5},+ ),+ (+ Annotated[int, validate_as(int).lt(100).gt(1)],+ {'type': 'integer', 'exclusiveMinimum': 1, 'exclusiveMaximum': 100},+ {'type': 'integer', 'exclusiveMinimum': 1, 'exclusiveMaximum': 100},+ ), ( Annotated[int, validate_as(int).gt(0) | validate_as(int).lt(100)], {'anyOf': [{'type': 'integer', 'exclusiveMinimum': 0}, {'type': 'integer', 'exclusiveMaximum': 100}]},