Skip to content

Commit 1c99576

Browse files
committed
Fix: GenConverter syntax errors with certain types
1 parent 56eda37 commit 1c99576

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

Diff for: src/cattrs/gen.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ def make_dict_structure_fn(
340340
lines.append(f"{i}except Exception as e:")
341341
i = f"{i} "
342342
lines.append(
343-
f"{i}e.__note__ = 'Structuring class {cl.__qualname__} @ attribute {an}'"
343+
f"{i}e.__note__ = 'Structuring class ' + {cl.__qualname__!r} + ' @ attribute', {an}"
344344
)
345345
lines.append(f"{i}errors.append(e)")
346346

@@ -352,15 +352,15 @@ def make_dict_structure_fn(
352352
]
353353

354354
post_lines.append(
355-
f" if errors: raise __c_cve('While structuring {cl.__name__}', errors, __cl)"
355+
f" if errors: raise __c_cve('While structuring ' + {cl.__name__!r}, errors, __cl)"
356356
)
357357
instantiation_lines = (
358358
[" try:"]
359359
+ [" return __cl("]
360360
+ [f" {line}" for line in invocation_lines]
361361
+ [" )"]
362362
+ [
363-
f" except Exception as exc: raise __c_cve('While structuring {cl.__name__}', [exc], __cl)"
363+
f" except Exception as exc: raise __c_cve('While structuring ' + {cl.__name__!r}, [exc], __cl)"
364364
]
365365
)
366366
else:
@@ -717,7 +717,7 @@ def make_mapping_structure_fn(
717717
lines.append(" errors.append(e)")
718718
lines.append(" if errors:")
719719
lines.append(
720-
f" raise IterableValidationError('While structuring {cl!r}', errors, __cattr_mapping_cl)"
720+
f' raise IterableValidationError("While structuring " + {repr(cl)!r}, errors, __cattr_mapping_cl)'
721721
)
722722
else:
723723
lines.append(f" res = {{{k_s}: {v_s} for k, v in mapping.items()}}")

0 commit comments

Comments
 (0)