Mr-Milk / python-hmr

🔄 Hot module reload for python, automatically reload your code when files are modified. No need to modify source code.
MIT License
29 stars 1 forks source link

How does HMR handle updating all references? #13

Open jgarvin opened 4 weeks ago

jgarvin commented 4 weeks ago

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?

Mr-Milk commented 4 weeks ago

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.