python-hmr icon indicating copy to clipboard operation
python-hmr copied to clipboard

How does HMR handle updating all references?

Open jgarvin opened this issue 1 year ago • 1 comments

In python if module A does a import moduleB then you reload module B, inside module A it will still be referring to the old version of module B. I was curious how you solved this, and I see __recursive_reload checking every attr of the given module recursively to find other modules that need reloading, but I don't see it updating those references. Does every module that imports module B need to explicitly call hmr.reload(moduleB) for this to work?

jgarvin avatar Oct 17 '24 23:10 jgarvin

Hi, thanks for asking. It's a recursive function that returns itself, so yes, it will reload all the modules that need to be reloaded.

You only need to call the hmr.reload for the highest level import.

Feel free to ask if you have further questions! I'm happy to answer.

Mr-Milk avatar Oct 18 '24 10:10 Mr-Milk