10000 bpo-43905: Expand dataclasses.astuple() and asdict() docs by akulakov · Pull Request #26154 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-43905: Expand dataclasses.astuple() and asdict() docs #26154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 8 commits into from
Nov 29, 2021
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Faile 10000 d to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Moved 'deepcopy' sentence to the first paragraph.
  • Loading branch information
akulakov authored May 24, 2021
commit 1b80a7a52789fd41e7f8a5810112447042a0637a
7 changes: 3 additions & 4 deletions Doc/library/dataclasses.rst
Original file line number Diff line number Diff line change
Expand Up @@ -349,16 +349,15 @@ Module contents
Converts the dataclass ``instance`` to a tuple (by using the
factory function ``tuple_factory``). Each dataclass is converted
to a tuple of its field values. dataclasses, dicts, lists, and
tuples are recursed into.
tuples are recursed into. Other objects are copied with
:func:`copy.deepcopy`.

Continuing from the previous example::

assert astuple(p) == (10, 20)
assert astuple(c) == ([(0, 0), (10, 4)],)

The tuple is a :func:`copy.deepcopy` of contained objects, which may
be an issue in some corner cases. To create a shallow copy, the
following workaround may be used::
To create a shallow copy, the following workaround may be used::

tuple(getattr(instance, field.name) for field in dataclasses.fields(instance))

Expand Down
0