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 bar.harel
Recipients bar.harel, docs@python
Date 2022-03-06.11:34:33
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1646566474.17.0.0323337902851.issue46938@roundup.psfhosted.org>
In-reply-to
Content
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__.
History
Date User Action Args
2022-03-06 11:34:34bar.harelsetrecipients: + bar.harel, docs@python
2022-03-06 11:34:34bar.harelsetmessageid: <1646566474.17.0.0323337902851.issue46938@roundup.psfhosted.org>
2022-03-06 11:34:34bar.harellinkissue46938 messages
2022-03-06 11:34:33bar.harelcreate