|
87 | 87 |
|
88 | 88 | BUILTIN_CONSTANTS = (None, False, True, NotImplemented) |
89 | 89 |
|
90 | | -def _stash_modules(main_module): |
| 90 | +def _stash_modules(main_module, original_main): |
91 | 91 | """pop imported variables to be saved by reference in the __dill_imported* attributes""" |
92 | | - modmap = _module_map(main_module) |
| 92 | + modmap = _module_map(original_main) |
93 | 93 | newmod = ModuleType(main_module.__name__) |
94 | 94 | original = {} |
95 | 95 | imported = [] |
@@ -136,6 +136,7 @@ def _stash_modules(main_module): |
136 | 136 | refimported += [(name, mod) for mod, name in imported_top_level] |
137 | 137 | message = "[dump_module] Variables saved by reference (refimported):\n" |
138 | 138 | logger.info(message + _format_log_dict(dict(refimported))) |
| 139 | + logger.debug("main namespace after _stash_modules(): %s", dir(newmod)) |
139 | 140 |
|
140 | 141 | return newmod, modmap |
141 | 142 | else: |
@@ -176,6 +177,7 @@ def _filter_vars(main_module, exclude, include, base_rules): |
176 | 177 | newmod = ModuleType(main_module.__name__) |
177 | 178 | newmod.__dict__.update(namespace) |
178 | 179 | _discard_added_variables(newmod, namespace) |
| 180 | + logger.debug("main namespace after _filter_vars(): %s", dir(newmod)) |
179 | 181 | return newmod |
180 | 182 |
|
181 | 183 | def _discard_added_variables(main, original_namespace): |
@@ -363,9 +365,12 @@ def dump_module( |
363 | 365 | if not isinstance(main, ModuleType): |
364 | 366 | raise TypeError("%r is not a module" % main) |
365 | 367 | original_main = main |
| 368 | + |
| 369 | + logger.debug("original main namespace: %s", dir(main)) |
366 | 370 | main = _filter_vars(main, exclude, include, base_rules) |
367 | 371 | if refimported: |
368 | | - main, modmap = _stash_modules(original_main) |
| 372 | + main, modmap = _stash_modules(main, original_main) |
| 373 | + |
369 | 374 | with _open(filename, 'wb', seekable=True) as file: |
370 | 375 | pickler = Pickler(file, protocol, **kwds) |
371 | 376 | pickler._main = main #FIXME: dill.settings are disabled |
|
0 commit comments