Message414613
Not sure if a continuance of https://bugs.python.org/issue44365 or not, but the suggestion to call super().__init__() in __post__init__ will cause infinite recursion if the superclass also contains __post__init__:
>>> @d
... class A:
... test: int
... def __post_init__(self):
... pass
>>> @d
... class B(A):
... test2: int
... def __post_init__(self):
... super().__init__(test=1)
>>> B(test2=1, test=3) <-- infinite recursion.
This is caused by line 564 (https://github.com/python/cpython/blob/4716f70c8543d12d18c64677af650d479b99edac/Lib/dataclasses.py#L564) checking for post init on current class, and calling it on self (child class).
Not sure if the bug is in the documentation/suggestion, or if it's a bug in the implementation, in which case we need to call the current class's __post_init__. |
|
Date |
User |
Action |
Args |
2022-03-06 11:34:34 | bar.harel | set | recipients:
+ bar.harel, docs@python |
2022-03-06 11:34:34 | bar.harel | set | messageid: <1646566474.17.0.0323337902851.issue46938@roundup.psfhosted.org> |
2022-03-06 11:34:34 | bar.harel | link | issue46938 messages |
2022-03-06 11:34:33 | bar.harel | create | |
|