From: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com> Date: Sun, 14 Apr 2024 00:14:43 +0000 (+0200) Subject: Simpler example of shallow dict export of a dataclass (#117812) X-Git-Tag: v3.13.0b1~438 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=f303651b45649392bf718f970793ad65d9ded0b8;p=thirdparty%2FPython%2Fcpython.git Simpler example of shallow dict export of a dataclass (#117812) --- diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst index 0b479f0d5699..fe56345f3a7f 100644 --- a/Doc/library/dataclasses.rst +++ b/Doc/library/dataclasses.rst @@ -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.