Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Save objects imported with an alias and top level modules by referenc…
…e in `dump_session(byref=TRUE)` Currently, `dump_session(byref=True)` misses some imported objects. For example: - If the session had a statement `import numpy as np`, it may find a reference to the `numpy` named as `np` in some internal module listed in `sys.resources`. But if the module was imported with a non-canonical name, like `import numpy as nump`, it won't find it at all. Mapping the objects by id in `modmap` solves the issue. Note that just types of objects usually imported under an alias must be looked up by id, otherwise common objects like singletons may be wrongly attributed to a module, and such reference in the module could change to a different object depending on its initialization and state. - If a object in the global scope is a top level module, like `math`, again `save_session` may find a reference to it in another module and it works. But if this module isn't referenced anywhere else, it won't be found because the function only looks for objects inside the `sys.resources` modules and not for the modules themselves. This commit introduces two new attributes to session modules saved by reference: - `__dill_imported_as`: a list with (module name, object name, object alias in session) - `__dill_imported_top_level`: a list with (module name, module alias in session) I did it this way for forwards (complete) and backwards (partial) compatibility. Oh, and I got rid of that nasty `exec()` call in `_restore_modules()`! ;)
- Loading branch information