[issue43965] dataclasses.replace breaks when __init__ is overrriden in subclass

2021-04-28 Thread Sebastian Speitel
Sebastian Speitel added the comment: Or maybe a cls argument which defaults to obj.__class__? -- ___ Python tracker ___ ___ Python-

[issue43965] dataclasses.replace breaks when __init__ is overrriden in subclass

2021-04-28 Thread Sebastian Speitel
Sebastian Speitel added the comment: One solution I thought of was to return not an object of the same instance, but one of the same dataclass, which would allow the implementation to traverse the class hierachy of the object and create an instance of the first dataclass-class (or class with

[issue43965] dataclasses.replace breaks when __init__ is overrriden in subclass

2021-04-28 Thread Eric V. Smith
Eric V. Smith added the comment: I'm open to suggestions on how this could be fixed, but I don't see how it's possible. I guess the best thing to do would be to fail if __init__() isn't the one that was generated by @dataclass. But that might be too pessimistic: the user could have provided

[issue43965] dataclasses.replace breaks when __init__ is overrriden in subclass

2021-04-28 Thread Sebastian Speitel
New submission from Sebastian Speitel : from dataclasses import dataclass, replace @dataclass() class A: a: int class B(A): def __init__(self): super().__init__(a=1) obj1 = B() obj2 = replace(obj1, a=2) File "/usr/lib/python3.9/dataclasses.py", line 1284, in replace ret