mirror of https://github.com/python/cpython
Simpler example of shallow dict export of a dataclass (#117812)
This commit is contained in:
parent
e7cce2a9c6
commit
f303651b45
|
@ -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…
Reference in New Issue