]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Simpler example of shallow dict export of a dataclass (#117812)
authorGouvernathor <44340603+Gouvernathor@users.noreply.github.com>
Sun, 14 Apr 2024 00:14:43 +0000 (02:14 +0200)
committerGitHub <noreply@github.com>
Sun, 14 Apr 2024 00:14:43 +0000 (17:14 -0700)
Doc/library/dataclasses.rst

index 0b479f0d569981ef851983b24f238af2f620e25c..fe56345f3a7fd2bb5ed7051febdb31dd39bbcf4a 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.