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 veky
Recipients NeilGirdhar, eric.smith, sobolevn, veky
Date 2022-02-19.07:51:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1645257087.62.0.557266399264.issue46757@roundup.psfhosted.org>
In-reply-to
Content
That "except AttributeError" approach is a powerful bug magnet, since it can very easily mask real attribute errors stemming from misspelled attribute names in the __post_init__ call itself. What you should _really_ do is

    def __post_init__(self):
        with contextlib.suppress(AttributeError):
            post_init = super().__post_init__
        post_init()

But of course, nobody will ever write that.

Raymond in his "super considered super" video (https://youtu.be/xKgELVmrqfs?t=2068) says the right thing to do is to make your own root which knows exactly what classes it manages, and drops the supercalls from them (after possibly verifying that all kwargs have actually been used and so on).

But in case of dataclasses, usually any class can serve as such a root, and the main reason people use dataclasses is to avoid boilerplate code. So I think it would be a nice compromise.
History
Date User Action Args
2022-02-19 07:51:27vekysetrecipients: + veky, eric.smith, NeilGirdhar, sobolevn
2022-02-19 07:51:27vekysetmessageid: <1645257087.62.0.557266399264.issue46757@roundup.psfhosted.org>
2022-02-19 07:51:27vekylinkissue46757 messages
2022-02-19 07:51:27vekycreate