-
Notifications
You must be signed in to change notification settings - Fork 49
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
reload() does not reload submodules #39
Comments
This needs more reflection than I thought: Reloading super-modulesWhat’s clear is that
Now, does the following reload file = import('a/file') # implicitly loads 'a'
reload(file) Unloading dependent modulesWhat is After the changes discussed in this issue, the semantics of |
This might be a good time to revisit if My first intuition is, that if I expect that a a = import('a')
file = import('a/file')
reload(file) then can you easily reload I think the most important consideration is to never leave modules in a broken state, i.e. never allow that two different objects to hold two different versions of the same module - this would be a nightmare to debug (and each module should be loaded only once and then referenced multiple times anyway). Can you achieve this with either approach? |
It absolutely does: ⟩⟩⟩ tree .
.
└── foo
├── __init__.py
└── bar.py
⟩⟩⟩ more foo/__init__.py
print ("foo")
⟩⟩⟩ more foo/bar.py
print ("foo/bar") import foo.bar
I guess this behaviour makes sense: submodules may expect that parent modules are set up correctly. This should only matter if the initialisers of these modules have side-effects, of course. I can’t think of very strong arguments for and against this behaviour actually. The ones I can think of at the moment are rather mundane:
|
For completeness’ sake, Python does not reload super-modules. So we should probably stay consistent with that. |
To answer your other concern:
Actually I think the opposite is true: references to modules are truly independent of each other, once they’re loaded. a = import('a')
b = import('a')
reload(a) This will not touch
Not easily, and as I’ve said above I actually don’t want to achieve this. However, this behaviour is inconsistent with Python. |
Yes, I think this is definitely the way to go! It is somewhat more complicated to achieve this with
For the first problem, you need to make sure that the shared libs you load have different paths in the file system, e.g. linking them to a temporary dir is enough. Maybe even symlinking. For the second, you probably don't need to do much, maybe having a shim for |
Yikes. I hadn’t even considered shared libraries, to be honest. The proposed solution only works as long as the shared library hasn’t itself got shared library dependencies (that might be recompiled), and it’s probably impractical to copy the whole dependency graph of shared libraries anyway. In that sense I might make it a conscious decision (properly documented, of course) to offer only limited support for shared libraries in S4 is currently unsupported by modules anyway and, if I don’t hear compelling testimony, never will be. I’d be more interested in getting R6 running but I don’t have the necessary knowledge for that. |
I don't think the shared libraries are too bad, but cannot say for sure until we try. R6 should be easy, it does not introduce any new namespaces like S4. R6 objects are just environments, so as long as modules can contain environments, you are fine. I am fairly sure that everything will just work, including cross module inheritance. |
Consider the following module:
Editing and reloading does not reload a submodule's changes:
Having
reload()
default to shallow reloading that only reloads the__init__
file doesn't make any sense. Either make shallow-whole-module reloading default or full deep reloading.The text was updated successfully, but these errors were encountered: