@@ -1092,8 +1092,7 @@ def list_schema(
1092
1092
1093
1093
1094
1094
class TuplePositionalSchema (TypedDict , total = False ):
1095
- type : Required [Literal ['tuple' ]]
1096
- mode : Required [Literal ['positional' ]]
1095
+ type : Required [Literal ['tuple-positional' ]]
1097
1096
items_schema : Required [List [CoreSchema ]]
1098
1097
extra_schema : CoreSchema
1099
1098
strict : bool
@@ -1132,8 +1131,7 @@ def tuple_positional_schema(
1132
1131
serialization: Custom serialization schema
1133
1132
"""
1134
1133
return dict_not_none (
1135
- type = 'tuple' ,
1136
- mode = 'positional' ,
1134
+ type = 'tuple-positional' ,
1137
1135
items_schema = items_schema ,
1138
1136
extra_schema = extra_schema ,
1139
1137
strict = strict ,
@@ -1144,8 +1142,7 @@ def tuple_positional_schema(
1144
1142
1145
1143
1146
1144
class TupleVariableSchema (TypedDict , total = False ):
1147
- type : Required [Literal ['tuple' ]]
1148
- mode : Literal ['variable' ]
1145
+ type : Required [Literal ['tuple-variable' ]]
1149
1146
items_schema : CoreSchema
1150
1147
min_length : int
1151
1148
max_length : int
@@ -1185,8 +1182,7 @@ def tuple_variable_schema(
1185
1182
serialization: Custom serialization schema
1186
1183
"""
1187
1184
return dict_not_none (
1188
- type = 'tuple' ,
1189
- mode = 'variable' ,
1185
+ type = 'tuple-variable' ,
1190
1186
items_schema = items_schema ,
1191
1187
min_length = min_length ,
1192
1188
max_length = max_length ,
@@ -1447,24 +1443,30 @@ def __call__(self, __input_value: Any, __info: ValidationInfo) -> Any: # pragma
1447
1443
...
1448
1444
1449
1445
1450
- class FunctionSchema (TypedDict , total = False ):
1451
- type : Required [Literal ['function' ]]
1452
- mode : Required [Literal ['before' , 'after' ]]
1446
+ class _FunctionSchema (TypedDict , total = False ):
1453
1447
function : Required [ValidatorFunction ]
1454
1448
schema : Required [CoreSchema ]
1455
1449
ref : str
1456
1450
metadata : Any
1457
1451
serialization : SerSchema
1458
1452
1459
1453
1454
+ class FunctionBeforeSchema (_FunctionSchema , total = False ):
1455
+ type : Required [Literal ['function-before' ]]
1456
+
1457
+
1458
+ class FunctionAfterSchema (_FunctionSchema , total = False ):
1459
+ type : Required [Literal ['function-after' ]]
1460
+
1461
+
1460
1462
def function_before_schema (
1461
1463
function : ValidatorFunction ,
1462
1464
schema : CoreSchema ,
1463
1465
* ,
1464
1466
ref : str | None = None ,
1465
1467
metadata : Any = None ,
1466
1468
serialization : SerSchema | None = None ,
1467
- ) -> FunctionSchema :
1469
+ ) -> FunctionBeforeSchema :
1468
1470
"""
1469
1471
Returns a schema that calls a validator function before validating the provided schema, e.g.:
1470
1472
@@ -1490,8 +1492,7 @@ def fn(v: Any, info: core_schema.ValidationInfo) -> str:
1490
1492
serialization: Custom serialization schema
1491
1493
"""
1492
1494
return dict_not_none (
1493
- type = 'function' ,
1494
- mode = 'before' ,
1495
+ type = 'function-before' ,
1495
1496
function = function ,
1496
1497
schema = schema ,
1497
1498
ref = ref ,
@@ -1507,7 +1508,7 @@ def function_after_schema(
1507
1508
ref : str | None = None ,
1508
1509
metadata : Any = None ,
1509
1510
serialization : SerSchema | None = None ,
1510
- ) -> FunctionSchema :
1511
+ ) -> FunctionAfterSchema :
1511
1512
"""
1512
1513
Returns a schema that calls a validator function after validating the provided schema, e.g.:
1513
1514
@@ -1531,13 +1532,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
1531
1532
serialization: Custom serialization schema
1532
1533
"""
1533
1534
return dict_not_none (
1534
- type = 'function' ,
1535
- mode = 'after' ,
1536
- function = function ,
1537
- schema = schema ,
1538
- ref = ref ,
1539
- metadata = metadata ,
1540
- serialization = serialization ,
1535
+ type = 'function-after' , function = function , schema = schema , ref = ref , metadata = metadata , serialization = serialization
1541
1536
)
1542
1537
1543
1538
@@ -1554,8 +1549,7 @@ def __call__(
1554
1549
1555
1550
1556
1551
class FunctionWrapSchema (TypedDict , total = False ):
1557
- type : Required [Literal ['function' ]]
1558
- mode : Required [Literal ['wrap' ]]
1552
+ type : Required [Literal ['function-wrap' ]]
1559
1553
function : Required [WrapValidatorFunction ]
1560
1554
schema : Required [CoreSchema ]
1561
1555
ref : str
@@ -1595,19 +1589,12 @@ def fn(v: str, validator: core_schema.CallableValidator, info: core_schema.Valid
1595
1589
serialization: Custom serialization schema
1596
1590
"""
1597
1591
return dict_not_none (
1598
- type = 'function' ,
1599
- mode = 'wrap' ,
1600
- function = function ,
1601
- schema = schema ,
1602
- ref = ref ,
1603
- metadata = metadata ,
1604
- serialization = serialization ,
1592
+ type = 'function-wrap' , function = function , schema = schema , ref = ref , metadata = metadata , serialization = serialization
1605
1593
)
1606
1594
1607
1595
1608
1596
class FunctionPlainSchema (TypedDict , total = False ):
1609
- type : Required [Literal ['function' ]]
1610
- mode : Required [Literal ['plain' ]]
1597
+ type : Required [Literal ['function-plain' ]]
1611
1598
function : Required [ValidatorFunction ]
1612
1599
ref : str
1613
1600
metadata : Any
@@ -1639,7 +1626,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
1639
1626
serialization: Custom serialization schema
1640
1627
"""
1641
1628
return dict_not_none (
1642
- type = 'function' , mode = ' plain' , function = function , ref = ref , metadata = metadata , serialization = serialization
1629
+ type = 'function- plain' , function = function , ref = ref , metadata = metadata , serialization = serialization
1643
1630
)
1644
1631
1645
1632
@@ -2638,7 +2625,8 @@ def definition_reference_schema(
2638
2625
FrozenSetSchema ,
2639
2626
GeneratorSchema ,
2640
2627
DictSchema ,
2641
- FunctionSchema ,
2628
+ FunctionBeforeSchema ,
2629
+ FunctionAfterSchema ,
2642
2630
FunctionWrapSchema ,
2643
2631
FunctionPlainSchema ,
2644
2632
WithDefaultSchema ,
@@ -2677,12 +2665,16 @@ def definition_reference_schema(
2677
2665
'is-subclass' ,
2678
2666
'callable' ,
2679
2667
'list' ,
2680
- 'tuple' ,
2668
+ 'tuple-positional' ,
2669
+ 'tuple-variable' ,
2681
2670
'set' ,
2682
2671
'frozenset' ,
2683
2672
'generator' ,
2684
2673
'dict' ,
2685
- 'function' ,
2674
+ 'function-before' ,
2675
+ 'function-after' ,
2676
+ 'function-wrap' ,
2677
+ 'function-plain' ,
2686
2678
'default' ,
2687
2679
'nullable' ,
2688
2680
'union' ,
0 commit comments