@@ -215,7 +215,7 @@ def make_dict_structure_fn(
215
215
_cattrs_use_linecache : bool = True ,
216
216
_cattrs_prefer_attrib_converters : bool = False ,
217
217
_cattrs_detailed_validation : bool = True ,
218
- ** kwargs ,
218
+ ** kwargs : AttributeOverride ,
219
219
) -> Callable [[Mapping [str , Any ], Any ], T ]:
220
220
"""Generate a specialized dict structuring function for an attrs class."""
221
221
@@ -326,6 +326,15 @@ def make_dict_structure_fn(
326
326
post_lines .append (
327
327
f" if errors: raise __c_cve('While structuring { cl .__name__ } ', errors, __cl)"
328
328
)
329
+ instantiation_lines = (
330
+ [" try:" ]
331
+ + [" return __cl(" ]
332
+ + [f" { line } " for line in invocation_lines ]
333
+ + [" )" ]
334
+ + [
335
+ f" except Exception as exc: raise __c_cve('While structuring { cl .__name__ } ', [exc], __cl)"
336
+ ]
337
+ )
329
338
else :
330
339
non_required = []
331
340
# The first loop deals with required args.
@@ -432,6 +441,9 @@ def make_dict_structure_fn(
432
441
)
433
442
else :
434
443
post_lines .append (f" res['{ ian } '] = o['{ kn } ']" )
444
+ instantiation_lines = (
445
+ [" return __cl(" ] + [f" { line } " for line in invocation_lines ] + [" )" ]
446
+ )
435
447
436
448
if _cattrs_forbid_extra_keys :
437
449
globs ["__c_a" ] = allowed_fields
@@ -452,9 +464,7 @@ def make_dict_structure_fn(
452
464
[f"def { fn_name } (o, _, *, { internal_arg_line } ):" ]
453
465
+ lines
454
466
+ post_lines
455
- + [" return __cl(" ]
456
- + [f" { line } " for line in invocation_lines ]
457
- + [" )" ]
467
+ + instantiation_lines
458
468
)
459
469
460
470
fname = _generate_unique_filename (cl , "structure" , reserve = _cattrs_use_linecache )
0 commit comments