[New-bugs-announce] [issue43965] dataclasses.replace breaks when __init__ is overrriden in subclass
Sebastian Speitel
report at bugs.python.org
Wed Apr 28 05:34:28 EDT 2021
New submission from Sebastian Speitel <sebastian.speitel at outlook.de>:
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.
----------
components: Library (Lib)
messages: 392174
nosy: SebastianSpeitel
priority: normal
severity: normal
status: open
title: dataclasses.replace breaks when __init__ is overrriden in subclass
type: behavior
versions: Python 3.7, Python 3.8, Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue43965>
_______________________________________
More information about the New-bugs-announce
mailing list