Wrap __post_init__
to check or force that Module.__post_init__
is called
#2733
Labels
Priority: P2 - no schedule
Best effort response and resolution. We have no plan to work on this at the moment.
We added a runtime check in #2535 to emit a "IncorrectPostInitOverrideError" when users forget to call
super().__post_init__()
from a custom__post_init__
method. That implementation only runs the check at the top-level though, so it's not going to catch internal Modules that override__post_init__
.e.g.
What I think we should do instead is to just wrap
__post_init__
on subclass instantiation to check (and possible even force) thatModule.__post_init__
is called.For forcing the only complex case is when users use inheritance and call their own parent-class
__post_init__
in some random order inside their child__post_init__
(I've seen this.), but I think there's a way for a wrapper to detect this and to only run in the outermost child-defined__post_init__
.The text was updated successfully, but these errors were encountered: