New submission from Bar Harel <bzvi7...@gmail.com>:
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__. ---------- assignee: docs@python components: Documentation, Library (Lib) messages: 414613 nosy: bar.harel, docs@python priority: normal severity: normal status: open title: dataclass __post_init__ recursion type: behavior versions: Python 3.10, Python 3.11, Python 3.9 _______________________________________ Python tracker <rep...@bugs.python.org> <https://bugs.python.org/issue46938> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com