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 NeilGirdhar
Recipients NeilGirdhar
Date 2022-02-15.11:13:27
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1644923607.6.0.495534870715.issue46757@roundup.psfhosted.org>
In-reply-to
Content
When defining a dataclass, it's possible to define a post-init (__post_init__) method to, for example, verify contracts.

Sometimes, when you inherit from another dataclass, that dataclass has its own post-init method.  If you want that method to also do its checks, you need to explicitly call it with super.  However, if that method doesn't exist calling it with super will crash.

Since you don't know whether your superclasses implement post-init or not, you're forced to check if the superclass has one or not, and call it if it does.

Essentially, post-init implements an "augmenting pattern" like __init__, ___enter__, __exit__, __array_finalize__, etc.  All such methods define an empty method at the top level so that child classes can safely call super.

Please consider adding such an empty method to dataclasses so that children who implement __post_init__ can safely call super.
History
Date User Action Args
2022-02-15 11:13:27NeilGirdharsetrecipients: + NeilGirdhar
2022-02-15 11:13:27NeilGirdharsetmessageid: <1644923607.6.0.495534870715.issue46757@roundup.psfhosted.org>
2022-02-15 11:13:27NeilGirdharlinkissue46757 messages
2022-02-15 11:13:27NeilGirdharcreate