MCPcopy
hub / github.com/pydantic/pydantic / test_annotated_validator_before

Function test_annotated_validator_before

tests/test_validators.py:64–72  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

62
63
64def test_annotated_validator_before() -> None:
65 FloatMaybeInf = Annotated[float, BeforeValidator(lambda x, _info: x if x != 'zero' else 0.0)]
66
67 class Model(BaseModel):
68 x: FloatMaybeInf
69
70 assert Model(x='zero').x == 0.0
71 assert Model(x=1.0).x == 1.0
72 assert Model(x='1.0').x == 1.0
73
74
75def test_annotated_validator_builtin() -> None:

Callers

nothing calls this directly

Calls 2

BeforeValidatorClass · 0.90
ModelClass · 0.70

Tested by

no test coverage detected