[New-bugs-announce] [issue35761] Allow dataclasses to be updated in place

Théophile Chevalier report at bugs.python.org
Thu Jan 17 09:23:09 EST 2019

New submission from Théophile Chevalier <theophile.chevalier at lenstra.fr>:

Calling dataclasses.replace(instance, **changes) returns a new object of the same type.

>From my understanding there is, however, no method to update in place fields of a dataclass from another one.

I propose to add dataclasses.update(instance_to_update, other_instance, **changes).

This would for instance allow one to change all fields of current object in a sturdy way.
In my case, I currently call obj.__dict__.update(other_obj.__dict__) to perform the operation, but I know it has always to be done pretty carefully.

If this is accepted, I'm willing to post the change.

messages: 333872
nosy: theophile
priority: normal
severity: normal
status: open
title: Allow dataclasses to be updated in place
type: enhancement
versions: Python 3.8

Python tracker <report at bugs.python.org>

More information about the New-bugs-announce mailing list