File tree Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Expand file tree Collapse file tree 1 file changed +20
-0
lines changed Original file line number Diff line number Diff line change @@ -1450,3 +1450,23 @@ def test_tagged_union_int_keys_json(benchmark):
1450
1450
v .validate_json ('{"x": 1001, "y": "1"}' )
1451
1451
1452
1452
benchmark (v .validate_json , payload )
1453
+
1454
+
1455
+ @pytest .mark .benchmark (group = 'field_function_validator' )
1456
+ def test_field_function_validator (benchmark ) -> None :
1457
+ def f (v : int , info : core_schema .FieldValidationInfo ) -> int :
1458
+ assert info .field_name == 'x'
1459
+ return v + 1
1460
+
1461
+ schema : core_schema .CoreSchema = core_schema .int_schema ()
1462
+
1463
+ for _ in range (100 ):
1464
+ schema = core_schema .field_after_validator_function (f , schema )
1465
+
1466
+ schema = core_schema .typed_dict_schema ({'x' : core_schema .typed_dict_field (schema )})
1467
+
1468
+ v = SchemaValidator (schema )
1469
+ payload = {'x' : 0 }
1470
+ assert v .validate_python (payload ) == {'x' : 100 }
1471
+
1472
+ benchmark (v .validate_python , payload )
You can’t perform that action at this time.
0 commit comments