]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.12] Simpler example of shallow dict export of a dataclass (GH-117812) (#117862)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 14 Apr 2024 00:22:35 +0000 (02:22 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2024 00:22:35 +0000 (00:22 +0000)
Simpler example of shallow dict export of a dataclass (GH-117812)
(cherry picked from commit f303651b45649392bf718f970793ad65d9ded0b8)

Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
Doc/library/dataclasses.rst

index c038d5513ac44c5b736d0166659777e894e59012..ae90d85e8d3149ef99c211cc341f3ae7d65a982e 100644 (file)
@@ -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.