https://github.com/python/cpython/commit/f303651b45649392bf718f970793ad65d9ded0b8
commit: f303651b45649392bf718f970793ad65d9ded0b8
branch: main
author: Gouvernathor <[email protected]>
committer: hauntsaninja <[email protected]>
date: 2024-04-13T17:14:43-07:00
summary:
Simpler example of shallow dict export of a dataclass (#117812)
files:
M Doc/library/dataclasses.rst
diff --git a/Doc/library/dataclasses.rst b/Doc/library/dataclasses.rst
index 0b479f0d569981..fe56345f3a7fd2 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.
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]