This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author SebastianSpeitel
Recipients SebastianSpeitel
Date 2021-04-28.09:34:28
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1619602468.72.0.276909030716.issue43965@roundup.psfhosted.org>
In-reply-to
Content
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
    return obj.__class__(**changes)
TypeError: __init__() got an unexpected keyword argument 'a'


When a class extends a dataclass and overrides `__init__`, `replace` still accepts it as a dataclass according to the PEP but fails at constructing, since the `__init__`-signature doesn't match anymore.
History
Date User Action Args
2021-04-28 09:34:28SebastianSpeitelsetrecipients: + SebastianSpeitel
2021-04-28 09:34:28SebastianSpeitelsetmessageid: <1619602468.72.0.276909030716.issue43965@roundup.psfhosted.org>
2021-04-28 09:34:28SebastianSpeitellinkissue43965 messages
2021-04-28 09:34:28SebastianSpeitelcreate