[issue35761] Allow dataclasses to be updated in place
Théophile Chevalier
report at bugs.python.org
Fri Jan 18 08:55:27 EST 2019
Théophile Chevalier <theophile.chevalier at lenstra.fr> 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 <report at bugs.python.org>
<https://bugs.python.org/issue35761>
_______________________________________
More information about the Python-bugs-list
mailing list