Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Over-writing of post_apply_hook by some HSI_Events #1360

Closed
tbhallett opened this issue May 19, 2024 · 2 comments · Fixed by #1361
Closed

Over-writing of post_apply_hook by some HSI_Events #1360

tbhallett opened this issue May 19, 2024 · 2 comments · Fixed by #1361
Assignees
Labels
bug Something isn't working

Comments

@tbhallett
Copy link
Collaborator

There are some instance of disease module writing instances of HSI_Events with a post_apply_hook method defined. This will over-write the method of the same name in the base class, preventing the functionality contained therein to operate (post_apply_hook in HSI_Event base class). It was a sort of "unwritten rule" (!) that the post_apply_hook part of an HSI_Event is reserved for use by the HSI_Event itself.

Examples of HSI_Event instance over-writing this method are:

def post_apply_hook(self):

def post_apply_hook(self):

There may be others...!

A simple fix would be for this logic to be placed at the end of the apply function in the respective HSI_Event.

But, a better fix would be allow the disease module do over-write the post_apply_hook method and create another method that is only called by the HealthSystem. e.g. in the HSI_Event base class:

  • put the current content of the post_apply_hook into _run_after_hsi_event,
  • over-write run (from the Event base class) to run apply, then post_apply_hook, then _run_after_hsi_event
@tbhallett tbhallett self-assigned this May 19, 2024
@matt-graham
Copy link
Collaborator

Another option would be for any classes which do overwrite the base class implementation of post_apply_hook to have to call the base class implementation within their implementation using

    super().post_apply_hook()

Overall though I think your proposed approach @tbhallett of creating a new 'private' method _run_after_hsi_event is probably nicer as it doesn't rely on people remembering to call the base class method in their implementation.

@tbhallett
Copy link
Collaborator Author

Thanks Matt. I'll give it a go

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants