[issue35710] Make dataclasses.field() accept another name for __init__ field's name
Change by Théophile Chevalier : -- nosy: +theophile ___ Python tracker <https://bugs.python.org/issue35710> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35761] Allow dataclasses to be updated in place
New submission from Théophile Chevalier : 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 <https://bugs.python.org/issue35761> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35761] Allow dataclasses to be updated in place
Théophile Chevalier added the comment: I understand your points, I'll give an example with a simplified version of my problem: import dataclasses import othermodule # is an external dependency @dataclass class City: name: str position: othermodule.Point # Point is a dataclass def update_position(self): obj = anymodule.get_position(name=self.name) # The classic solution would be to do self.position.x = obj.x self.position.y = obj.y # what if othermodule adds z (altitude) to Point? # we could imagine: dataclasses.update(self.position, obj) # I'm currently doing: self.position.__dict__.update(obj.__dict__) Maybe I simply handle the issue the wrong way, so my dataclass proposal is out of scope. -- ___ Python tracker <https://bugs.python.org/issue35761> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com
[issue35761] Allow dataclasses to be updated in place
Théophile Chevalier added the comment: I cannot do self.position = obj because I have references on position elsewhere. -- ___ Python tracker <https://bugs.python.org/issue35761> ___ ___ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com