@@ -1629,6 +1629,7 @@ class GeneralValidatorFunctionSchema(TypedDict):
1629
1629
class FieldValidatorFunctionSchema (TypedDict ):
1630
1630
type : Literal ['field' ]
1631
1631
function : FieldValidatorFunction
1632
+ field_name : str
1632
1633
1633
1634
1634
1635
ValidationFunction = Union [NoInfoValidatorFunctionSchema , FieldValidatorFunctionSchema , GeneralValidatorFunctionSchema ]
@@ -1691,6 +1692,7 @@ def fn(v: bytes) -> str:
1691
1692
1692
1693
def field_before_validator_function (
1693
1694
function : FieldValidatorFunction ,
1695
+ field_name : str ,
1694
1696
schema : CoreSchema ,
1695
1697
* ,
1696
1698
ref : str | None = None ,
@@ -1710,7 +1712,7 @@ def fn(v: bytes, info: core_schema.FieldValidationInfo) -> str:
1710
1712
return v.decode() + 'world'
1711
1713
1712
1714
func_schema = core_schema.field_before_validator_function(
1713
- function=fn, schema=core_schema.str_schema()
1715
+ function=fn, field_name='a', schema=core_schema.str_schema()
1714
1716
)
1715
1717
schema = core_schema.typed_dict_schema({'a': core_schema.typed_dict_field(func_schema)})
1716
1718
@@ -1720,14 +1722,15 @@ def fn(v: bytes, info: core_schema.FieldValidationInfo) -> str:
1720
1722
1721
1723
Args:
1722
1724
function: The validator function to call
1725
+ field_name: The name of the field
1723
1726
schema: The schema to validate the output of the validator function
1724
1727
ref: optional unique identifier of the schema, used to reference the schema in other places
1725
1728
metadata: Any other information you want to include with the schema, not used by pydantic-core
1726
1729
serialization: Custom serialization schema
1727
1730
"""
1728
1731
return _dict_not_none (
1729
1732
type = 'function-before' ,
1730
- function = {'type' : 'field' , 'function' : function },
1733
+ function = {'type' : 'field' , 'function' : function , 'field_name' : field_name },
1731
1734
schema = schema ,
1732
1735
ref = ref ,
1733
1736
metadata = metadata ,
@@ -1826,6 +1829,7 @@ def fn(v: str) -> str:
1826
1829
1827
1830
def field_after_validator_function (
1828
1831
function : FieldValidatorFunction ,
1832
+ field_name : str ,
1829
1833
schema : CoreSchema ,
1830
1834
* ,
1831
1835
ref : str | None = None ,
@@ -1845,7 +1849,7 @@ def fn(v: str, info: core_schema.FieldValidationInfo) -> str:
1845
1849
return v + 'world'
1846
1850
1847
1851
func_schema = core_schema.field_after_validator_function(
1848
- function=fn, schema=core_schema.str_schema()
1852
+ function=fn, field_name='a', schema=core_schema.str_schema()
1849
1853
)
1850
1854
schema = core_schema.typed_dict_schema({'a': core_schema.typed_dict_field(func_schema)})
1851
1855
@@ -1855,14 +1859,15 @@ def fn(v: str, info: core_schema.FieldValidationInfo) -> str:
1855
1859
1856
1860
Args:
1857
1861
function: The validator function to call after the schema is validated
1862
+ field_name: The name of the field
1858
1863
schema: The schema to validate before the validator function
1859
1864
ref: optional unique identifier of the schema, used to reference the schema in other places
1860
1865
metadata: Any other information you want to include with the schema, not used by pydantic-core
1861
1866
serialization: Custom serialization schema
1862
1867
"""
1863
1868
return _dict_not_none (
1864
1869
type = 'function-after' ,
1865
- function = {'type' : 'field' , 'function' : function },
1870
+ function = {'type' : 'field' , 'function' : function , 'field_name' : field_name },
1866
1871
schema = schema ,
1867
1872
ref = ref ,
1868
1873
metadata = metadata ,
@@ -1942,6 +1947,7 @@ class GeneralWrapValidatorFunctionSchema(TypedDict):
1942
1947
class FieldWrapValidatorFunctionSchema (TypedDict ):
1943
1948
type : Literal ['field' ]
1944
1949
function : FieldWrapValidatorFunction
1950
+ field_name : str
1945
1951
1946
1952
1947
1953
WrapValidatorFunction = Union [
@@ -2053,6 +2059,7 @@ def fn(
2053
2059
2054
2060
def field_wrap_validator_function (
2055
2061
function : FieldWrapValidatorFunction ,
2062
+ field_name : str ,
2056
2063
schema : CoreSchema ,
2057
2064
* ,
2058
2065
ref : str | None = None ,
@@ -2078,7 +2085,7 @@ def fn(
2078
2085
return validator(v) + 'world'
2079
2086
2080
2087
func_schema = core_schema.field_wrap_validator_function(
2081
- function=fn, schema=core_schema.str_schema()
2088
+ function=fn, field_name='a', schema=core_schema.str_schema()
2082
2089
)
2083
2090
schema = core_schema.typed_dict_schema({'a': core_schema.typed_dict_field(func_schema)})
2084
2091
@@ -2088,14 +2095,15 @@ def fn(
2088
2095
2089
2096
Args:
2090
2097
function: The validator function to call
2098
+ field_name: The name of the field
2091
2099
schema: The schema to validate the output of the validator function
2092
2100
ref: optional unique identifier of the schema, used to reference the schema in other places
2093
2101
metadata: Any other information you want to include with the schema, not used by pydantic-core
2094
2102
serialization: Custom serialization schema
2095
2103
"""
2096
2104
return _dict_not_none (
2097
2105
type = 'function-wrap' ,
2098
- function = {'type' : 'field' , 'function' : function },
2106
+ function = {'type' : 'field' , 'function' : function , 'field_name' : field_name },
2099
2107
schema = schema ,
2100
2108
ref = ref ,
2101
2109
metadata = metadata ,
@@ -2187,6 +2195,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
2187
2195
2188
2196
def field_plain_validator_function (
2189
2197
function : FieldValidatorFunction ,
2198
+ field_name : str ,
2190
2199
* ,
2191
2200
ref : str | None = None ,
2192
2201
metadata : Any = None ,
@@ -2204,7 +2213,7 @@ def fn(v: Any, info: core_schema.FieldValidationInfo) -> str:
2204
2213
assert info.field_name is not None
2205
2214
return str(v) + 'world'
2206
2215
2207
- func_schema = core_schema.field_plain_validator_function(function=fn)
2216
+ func_schema = core_schema.field_plain_validator_function(function=fn, field_name='a' )
2208
2217
schema = core_schema.typed_dict_schema({'a': core_schema.typed_dict_field(func_schema)})
2209
2218
2210
2219
v = SchemaValidator(schema)
@@ -2213,13 +2222,14 @@ def fn(v: Any, info: core_schema.FieldValidationInfo) -> str:
2213
2222
2214
2223
Args:
2215
2224
function: The validator function to call
2225
+ field_name: The name of the field
2216
2226
ref: optional unique identifier of the schema, used to reference the schema in other places
2217
2227
metadata: Any other information you want to include with the schema, not used by pydantic-core
2218
2228
serialization: Custom serialization schema
2219
2229
"""
2220
2230
return _dict_not_none (
2221
2231
type = 'function-plain' ,
2222
- function = {'type' : 'field' , 'function' : function },
2232
+ function = {'type' : 'field' , 'function' : function , 'field_name' : field_name },
2223
2233
ref = ref ,
2224
2234
metadata = metadata ,
2225
2235
serialization = serialization ,
0 commit comments