Skip to content
Merged
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/cattrs/gen.py
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@ def make_dict_structure_fn(
lines.append(f"{i}except Exception as e:")
i = f"{i} "
lines.append(
f"{i}e.__note__ = 'Structuring class {cl.__qualname__} @ attribute {an}'"
f"{i}e.__note__ = 'Structuring class ' + {cl.__qualname__!r} + ' @ attribute {an}'"
)
lines.append(f"{i}errors.append(e)")

Expand All @@ -352,15 +352,15 @@ def make_dict_structure_fn(
]

post_lines.append(
f" if errors: raise __c_cve('While structuring {cl.__name__}', errors, __cl)"
f" if errors: raise __c_cve('While structuring ' + {cl.__name__!r}, errors, __cl)"
)
instantiation_lines = (
[" try:"]
+ [" return __cl("]
+ [f" {line}" for line in invocation_lines]
+ [" )"]
+ [
f" except Exception as exc: raise __c_cve('While structuring {cl.__name__}', [exc], __cl)"
f" except Exception as exc: raise __c_cve('While structuring ' + {cl.__name__!r}, [exc], __cl)"
]
)
else:
Expand Down Expand Up @@ -717,7 +717,7 @@ def make_mapping_structure_fn(
lines.append(" errors.append(e)")
lines.append(" if errors:")
lines.append(
f" raise IterableValidationError('While structuring {cl!r}', errors, __cattr_mapping_cl)"
f" raise IterableValidationError('While structuring ' + {repr(cl)!r}, errors, __cattr_mapping_cl)"

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This might look odd at first glance - the first repr() gets a string representation of the class and the second repr (!r) turns said string into a string literal

)
else:
lines.append(f" res = {{{k_s}: {v_s} for k, v in mapping.items()}}")
Expand Down