File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 22
33## 23.2.0 (UNRELEASED)
44
5+ - Fix ` format_exception ` parameter working for recursive calls to ` transform_error `
6+ ([ #389 ] ( https://github.com/python-attrs/cattrs/issues/389 )
57- Use [ PDM] ( https://pdm.fming.dev/latest/ ) instead of Poetry.
68- _ cattrs_ is now linted with [ Ruff] ( https://beta.ruff.rs/docs/ ) .
79- Fix TypedDicts with periods in their field names.
Original file line number Diff line number Diff line change @@ -89,7 +89,7 @@ def transform_error(
8989 for exc , note in with_notes :
9090 p = f"{ path } [{ note .index !r} ]"
9191 if isinstance (exc , (ClassValidationError , IterableValidationError )):
92- errors .extend (transform_error (exc , p ))
92+ errors .extend (transform_error (exc , p , format_exception ))
9393 else :
9494 errors .append (f"{ format_exception (exc , note .type )} @ { p } " )
9595 for exc in without :
@@ -99,7 +99,7 @@ def transform_error(
9999 for exc , note in with_notes :
100100 p = f"{ path } .{ note .name } "
101101 if isinstance (exc , (ClassValidationError , IterableValidationError )):
102- errors .extend (transform_error (exc , p ))
102+ errors .extend (transform_error (exc , p , format_exception ))
103103 else :
104104 errors .append (f"{ format_exception (exc , note .type )} @ { p } " )
105105 for exc in without :
Original file line number Diff line number Diff line change @@ -227,6 +227,25 @@ class C:
227227 ]
228228
229229
230+ def test_custom_error_fn_nested (c : Converter ) -> None :
231+ def my_format (exc , type ):
232+ if isinstance (exc , TypeError ):
233+ return "Must be correct type"
234+ return format_exception (exc , type )
235+
236+ @define
237+ class C :
238+ a : Dict [str , int ]
239+
240+ try :
241+ c .structure ({"a" : {"a" : "str" , "b" : 1 , "c" : None }}, C )
242+ except Exception as exc :
243+ assert transform_error (exc , format_exception = my_format ) == [
244+ "invalid value for type, expected int @ $.a['a']" ,
245+ "Must be correct type @ $.a['c']" ,
246+ ]
247+
248+
230249def test_typeddict_attribute_errors (c : Converter ) -> None :
231250 """TypedDict errors are correctly generated."""
232251
You can’t perform that action at this time.
0 commit comments