Message413283
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. |
|
Date |
User |
Action |
Args |
2022-02-15 11:13:27 | NeilGirdhar | set | recipients:
+ NeilGirdhar |
2022-02-15 11:13:27 | NeilGirdhar | set | messageid: <1644923607.6.0.495534870715.issue46757@roundup.psfhosted.org> |
2022-02-15 11:13:27 | NeilGirdhar | link | issue46757 messages |
2022-02-15 11:13:27 | NeilGirdhar | create | |
|