mirror of
https://github.com/python/cpython.git
synced 2025-09-30 12:21:51 +00:00
[3.12] Simpler example of shallow dict export of a dataclass (GH-117812) (#117862)
Simpler example of shallow dict export of a dataclass (GH-117812)
(cherry picked from commit f303651b45
)
Co-authored-by: Gouvernathor <44340603+Gouvernathor@users.noreply.github.com>
This commit is contained in:
parent
222d16a18c
commit
efeb8a24b8
1 changed files with 1 additions and 1 deletions
|
@ -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.
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue