[issue43905] dataclasses.astuple does deepcopy on all fields

2021-05-20 Thread Erik Carstensen
Erik Carstensen added the comment: Would it make sense to make dataclasses iterable, like so? def __iter__(self): return (getattr(self, field.name) for field in fields(self)) With that in place, deprecating astuple would maybe be less disruptive? -- _

[issue43905] dataclasses.astuple does deepcopy on all fields

2021-05-20 Thread Eric V. Smith
Eric V. Smith added the comment: No, iteration is explicitly a non-goal of PEP 557. See the section on namedtuple for why: https://www.python.org/dev/peps/pep-0557/#why-not-just-use-namedtuple -- ___ Python tracker

[issue43905] dataclasses.astuple does deepcopy on all fields

2021-06-21 Thread Andrei Kulakov
Andrei Kulakov added the comment: I've added a PR here: https://github.com/python/cpython/pull/26154 -- ___ Python tracker ___ ___

[issue43905] dataclasses.astuple does deepcopy on all fields

2021-04-21 Thread Erik Carstensen
New submission from Erik Carstensen : 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 @dataclasses.dataclass class Foo: key: ob

[issue43905] dataclasses.astuple does deepcopy on all fields

2021-04-21 Thread Eric V. Smith
Eric V. Smith added the comment: Unfortunately this can't be changed, although I suppose it should be documented. In general I think this API was a mistake, and should not have been added. There are just too many cases where it doesn't do what you want, or where it fails. I'd like to deprec

[issue43905] dataclasses.astuple does deepcopy on all fields

2021-04-21 Thread Serhiy Storchaka
Serhiy Storchaka added the comment: Why deepcopy is used at all? It is a very specific feature which should not be used by default. If you want to make a deep copy of fields, you can call copy.deepcopy() explicitly. copy.deepcopy(dataclasses.astuple(obj)) or dataclasses.astuple(cop

[issue43905] dataclasses.astuple does deepcopy on all fields

2021-04-21 Thread Eric V. Smith
Eric V. Smith added the comment: The reason for the deep copying was to support changing a hierarchy of dataclasses into something that could be JSON serialized. But it didn't really work out. It recurses into dataclasses, namedtuples, lists, tuples, and dicts, and deep copies everything els

[issue43905] dataclasses.astuple does deepcopy on all fields

2021-05-15 Thread Andrei Kulakov
Change by Andrei Kulakov : -- keywords: +patch nosy: +andrei.avk nosy_count: 3.0 -> 4.0 pull_requests: +24788 stage: -> patch review pull_request: https://github.com/python/cpython/pull/26154 ___ Python tracker