@@ -1139,8 +1139,7 @@ def list_schema(
1139
1139
1140
1140
1141
1141
class TuplePositionalSchema (TypedDict , total = False ):
1142
- type : Required [Literal ['tuple' ]]
1143
- mode : Required [Literal ['positional' ]]
1142
+ type : Required [Literal ['tuple-positional' ]]
1144
1143
items_schema : Required [List [CoreSchema ]]
1145
1144
extra_schema : CoreSchema
1146
1145
strict : bool
@@ -1179,8 +1178,7 @@ def tuple_positional_schema(
1179
1178
serialization: Custom serialization schema
1180
1179
"""
1181
1180
return dict_not_none (
1182
- type = 'tuple' ,
1183
- mode = 'positional' ,
1181
+ type = 'tuple-positional' ,
1184
1182
items_schema = list (items_schema ),
1185
1183
extra_schema = extra_schema ,
1186
1184
strict = strict ,
@@ -1191,8 +1189,7 @@ def tuple_positional_schema(
1191
1189
1192
1190
1193
1191
class TupleVariableSchema (TypedDict , total = False ):
1194
- type : Required [Literal ['tuple' ]]
1195
- mode : Literal ['variable' ]
1192
+ type : Required [Literal ['tuple-variable' ]]
1196
1193
items_schema : CoreSchema
1197
1194
min_length : int
1198
1195
max_length : int
@@ -1232,8 +1229,7 @@ def tuple_variable_schema(
1232
1229
serialization: Custom serialization schema
1233
1230
"""
1234
1231
return dict_not_none (
1235
- type = 'tuple' ,
1236
- mode = 'variable' ,
1232
+ type = 'tuple-variable' ,
1237
1233
items_schema = items_schema ,
1238
1234
min_length = min_length ,
1239
1235
max_length = max_length ,
@@ -1509,24 +1505,26 @@ class GeneralValidatorFunctionSchema(TypedDict):
1509
1505
function : GeneralValidatorFunction
1510
1506
1511
1507
1512
- class FunctionSchema (TypedDict , total = False ):
1513
- type : Required [Literal ['function' ]]
1508
+ class _FunctionSchema (TypedDict , total = False ):
1514
1509
function : Required [Union [FieldValidatorFunctionSchema , GeneralValidatorFunctionSchema ]]
1515
- mode : Required [Literal ['before' , 'after' ]]
1516
1510
schema : Required [CoreSchema ]
1517
1511
ref : str
1518
1512
metadata : Any
1519
1513
serialization : SerSchema
1520
1514
1521
1515
1516
+ class FunctionBeforeSchema (_FunctionSchema , total = False ):
1517
+ type : Required [Literal ['function-before' ]]
1518
+
1519
+
1522
1520
def field_before_validation_function (
1523
1521
function : FieldValidatorFunction ,
1524
1522
schema : CoreSchema ,
1525
1523
* ,
1526
1524
ref : str | None = None ,
1527
1525
metadata : Any = None ,
1528
1526
serialization : SerSchema | None = None ,
1529
- ) -> FunctionSchema :
1527
+ ) -> FunctionBeforeSchema :
1530
1528
"""
1531
1529
Returns a schema that calls a validator function before validating
1532
1530
the provided **model field** schema, e.g.:
@@ -1556,8 +1554,7 @@ def fn(v: bytes, info: core_schema.ModelFieldValidationInfo) -> str:
1556
1554
serialization: Custom serialization schema
1557
1555
"""
1558
1556
return dict_not_none (
1559
- type = 'function' ,
1560
- mode = 'before' ,
1557
+ type = 'function-before' ,
1561
1558
function = {'type' : 'field' , 'function' : function },
1562
1559
schema = schema ,
1563
1560
ref = ref ,
@@ -1573,7 +1570,7 @@ def general_before_validation_function(
1573
1570
ref : str | None = None ,
1574
1571
metadata : Any = None ,
1575
1572
serialization : SerSchema | None = None ,
1576
- ) -> FunctionSchema :
1573
+ ) -> FunctionBeforeSchema :
1577
1574
"""
1578
1575
Returns a schema that calls a validator function before validating the provided schema, e.g.:
1579
1576
@@ -1599,8 +1596,7 @@ def fn(v: Any, info: core_schema.ValidationInfo) -> str:
1599
1596
serialization: Custom serialization schema
1600
1597
"""
1601
1598
return dict_not_none (
1602
- type = 'function' ,
1603
- mode = 'before' ,
1599
+ type = 'function-before' ,
1604
1600
function = {'type' : 'general' , 'function' : function },
1605
1601
schema = schema ,
1606
1602
ref = ref ,
@@ -1609,14 +1605,18 @@ def fn(v: Any, info: core_schema.ValidationInfo) -> str:
1609
1605
)
1610
1606
1611
1607
1608
+ class FunctionAfterSchema (_FunctionSchema , total = False ):
1609
+ type : Required [Literal ['function-after' ]]
1610
+
1611
+
1612
1612
def field_after_validation_function (
1613
1613
function : FieldValidatorFunction ,
1614
1614
schema : CoreSchema ,
1615
1615
* ,
1616
1616
ref : str | None = None ,
1617
1617
metadata : Any = None ,
1618
1618
serialization : SerSchema | None = None ,
1619
- ) -> FunctionSchema :
1619
+ ) -> FunctionAfterSchema :
1620
1620
"""
1621
1621
Returns a schema that calls a validator function after validating
1622
1622
the provided **model field** schema, e.g.:
@@ -1646,8 +1646,7 @@ def fn(v: str, info: core_schema.ModelFieldValidationInfo) -> str:
1646
1646
serialization: Custom serialization schema
1647
1647
"""
1648
1648
return dict_not_none (
1649
- type = 'function' ,
1650
- mode = 'after' ,
1649
+ type = 'function-after' ,
1651
1650
function = {'type' : 'field' , 'function' : function },
1652
1651
schema = schema ,
1653
1652
ref = ref ,
@@ -1663,7 +1662,7 @@ def general_after_validation_function(
1663
1662
ref : str | None = None ,
1664
1663
metadata : Any = None ,
1665
1664
serialization : SerSchema | None = None ,
1666
- ) -> FunctionSchema :
1665
+ ) -> FunctionAfterSchema :
1667
1666
"""
1668
1667
Returns a schema that calls a validator function after validating the provided schema, e.g.:
1669
1668
@@ -1687,8 +1686,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
1687
1686
serialization: Custom serialization schema
1688
1687
"""
1689
1688
return dict_not_none (
1690
- type = 'function' ,
1691
- mode = 'after' ,
1689
+ type = 'function-after' ,
1692
1690
function = {'type' : 'general' , 'function' : function },
1693
1691
schema = schema ,
1694
1692
ref = ref ,
@@ -1727,9 +1725,8 @@ class GeneralWrapValidatorFunctionSchema(TypedDict):
1727
1725
1728
1726
1729
1727
class WrapFunctionSchema (TypedDict , total = False ):
1730
- type : Required [Literal ['function' ]]
1728
+ type : Required [Literal ['function-wrap ' ]]
1731
1729
function : Required [Union [GeneralWrapValidatorFunctionSchema , FieldWrapValidatorFunctionSchema ]]
1732
- mode : Required [Literal ['wrap' ]]
1733
1730
schema : Required [CoreSchema ]
1734
1731
ref : str
1735
1732
metadata : Any
@@ -1768,8 +1765,7 @@ def fn(v: str, validator: core_schema.CallableValidator, info: core_schema.Valid
1768
1765
serialization: Custom serialization schema
1769
1766
"""
1770
1767
return dict_not_none (
1771
- type = 'function' ,
1772
- mode = 'wrap' ,
1768
+ type = 'function-wrap' ,
1773
1769
function = {'type' : 'general' , 'function' : function },
1774
1770
schema = schema ,
1775
1771
ref = ref ,
@@ -1817,8 +1813,7 @@ def fn(v: bytes, validator: core_schema.CallableValidator, info: core_schema.Mod
1817
1813
serialization: Custom serialization schema
1818
1814
"""
1819
1815
return dict_not_none (
1820
- type = 'function' ,
1821
- mode = 'wrap' ,
1816
+ type = 'function-wrap' ,
1822
1817
function = {'type' : 'field' , 'function' : function },
1823
1818
schema = schema ,
1824
1819
ref = ref ,
@@ -1828,8 +1823,7 @@ def fn(v: bytes, validator: core_schema.CallableValidator, info: core_schema.Mod
1828
1823
1829
1824
1830
1825
class PlainFunctionSchema (TypedDict , total = False ):
1831
- type : Required [Literal ['function' ]]
1832
- mode : Required [Literal ['plain' ]]
1826
+ type : Required [Literal ['function-plain' ]]
1833
1827
function : Required [Union [FieldValidatorFunctionSchema , GeneralValidatorFunctionSchema ]]
1834
1828
ref : str
1835
1829
metadata : Any
@@ -1865,8 +1859,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
1865
1859
serialization: Custom serialization schema
1866
1860
"""
1867
1861
return dict_not_none (
1868
- type = 'function' ,
1869
- mode = 'plain' ,
1862
+ type = 'function-plain' ,
1870
1863
function = {'type' : 'general' , 'function' : function },
1871
1864
ref = ref ,
1872
1865
metadata = metadata ,
@@ -1909,8 +1902,7 @@ def fn(v: Any, info: core_schema.ModelFieldValidationInfo) -> str:
1909
1902
serialization: Custom serialization schema
1910
1903
"""
1911
1904
return dict_not_none (
1912
- type = 'function' ,
1913
- mode = 'plain' ,
1905
+ type = 'function-plain' ,
1914
1906
function = {'type' : 'field' , 'function' : function },
1915
1907
ref = ref ,
1916
1908
metadata = metadata ,
@@ -3068,7 +3060,8 @@ def definition_reference_schema(
3068
3060
FrozenSetSchema ,
3069
3061
GeneratorSchema ,
3070
3062
DictSchema ,
3071
- FunctionSchema ,
3063
+ FunctionAfterSchema ,
3064
+ FunctionBeforeSchema ,
3072
3065
WrapFunctionSchema ,
3073
3066
PlainFunctionSchema ,
3074
3067
WithDefaultSchema ,
@@ -3109,12 +3102,16 @@ def definition_reference_schema(
3109
3102
'is-subclass' ,
3110
3103
'callable' ,
3111
3104
'list' ,
3112
- 'tuple' ,
3105
+ 'tuple-positional' ,
3106
+ 'tuple-variable' ,
3113
3107
'set' ,
3114
3108
'frozenset' ,
3115
3109
'generator' ,
3116
3110
'dict' ,
3117
- 'function' ,
3111
+ 'function-after' ,
3112
+ 'function-before' ,
3113
+ 'function-wrap' ,
3114
+ 'function-plain' ,
3118
3115
'default' ,
3119
3116
'nullable' ,
3120
3117
'union' ,
0 commit comments