Author mandolaerik
Recipients mandolaerik
Date 2021-04-21.12:19:16
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
It seems that the 'dataclass.astuple' function does a deepcopy of all fields. This is not documented. Two problems:

1. Dictionary keys that rely on object identity are ruined:
    import dataclasses
    class Foo:
        key: object
    key = object()
    lut = {key: 5}
    (y,) = dataclasses.astuple(Foo(x))
    # KeyError

2. dataclasses can only be converted to a tuple if all fields are serializable:

    import dataclasses
    class Foo:
        f: object
    foo = Foo(open(''))


TypeError: cannot pickle '_io.TextIOWrapper' object

In my use case, I just want a list of all fields. I can do the following as a workaround:
  (getattr(foo, for field in dataclasses.fields(foo))

Tested on Python 3.8.7 and 3.7.9.
Date User Action Args
2021-04-21 12:19:17mandolaeriksetrecipients: + mandolaerik
2021-04-21 12:19:17mandolaeriksetmessageid: <>
2021-04-21 12:19:17mandolaeriklinkissue43905 messages
2021-04-21 12:19:16mandolaerikcreate