Skip to content

Commit

Permalink
Better example of dict shallow copy
Browse files Browse the repository at this point in the history
  • Loading branch information
Gouvernathor authored Apr 12, 2024
1 parent 39a6b29 commit 48cb95e
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,7 @@ Module contents

To create a shallow copy, the following workaround may be used::

dict((field.name, getattr(obj, field.name)) for field in fields(obj))
{field.name: getattr(obj, field.name) for field in fields(obj)}

:func:`!asdict` raises :exc:`TypeError` if ``obj`` is not a dataclass
instance.
Expand Down

0 comments on commit 48cb95e

Please sign in to comment.