Skip to content

Commit 4244d3b

Browse files
committed
fix _stash_modules() arguments
1 parent 71b4f77 commit 4244d3b

File tree

3 files changed

+11
-4
lines changed

3 files changed

+11
-4
lines changed

dill/_dill.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@
3939
from dill import logging
4040
from .logging import adapter as logger
4141
from .logging import trace as _trace
42+
_logger = logging.getLogger(__name__)
4243

4344
import os
4445
import sys
@@ -1350,6 +1351,7 @@ def _save_module_dict(pickler, main_dict):
13501351
is_builtin = _is_builtin_module(main)
13511352
pickler.write(MARK + DICT) # don't need to memoize
13521353
for name, value in main_dict.items():
1354+
_logger.debug("Pickling %r (%s)", name, type(value).__name__)
13531355
pickler.save(name)
13541356
try:
13551357
if pickler.save(value):

dill/session.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,9 +87,9 @@
8787

8888
BUILTIN_CONSTANTS = (None, False, True, NotImplemented)
8989

90-
def _stash_modules(main_module):
90+
def _stash_modules(main_module, original_main):
9191
"""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)
9393
newmod = ModuleType(main_module.__name__)
9494
original = {}
9595
imported = []
@@ -136,6 +136,7 @@ def _stash_modules(main_module):
136136
refimported += [(name, mod) for mod, name in imported_top_level]
137137
message = "[dump_module] Variables saved by reference (refimported):\n"
138138
logger.info(message + _format_log_dict(dict(refimported)))
139+
logger.debug("main namespace after _stash_modules(): %s", dir(newmod))
139140

140141
return newmod, modmap
141142
else:
@@ -176,6 +177,7 @@ def _filter_vars(main_module, exclude, include, base_rules):
176177
newmod = ModuleType(main_module.__name__)
177178
newmod.__dict__.update(namespace)
178179
_discard_added_variables(newmod, namespace)
180+
logger.debug("main namespace after _filter_vars(): %s", dir(newmod))
179181
return newmod
180182

181183
def _discard_added_variables(main, original_namespace):
@@ -363,9 +365,12 @@ def dump_module(
363365
if not isinstance(main, ModuleType):
364366
raise TypeError("%r is not a module" % main)
365367
original_main = main
368+
369+
logger.debug("original main namespace: %s", dir(main))
366370
main = _filter_vars(main, exclude, include, base_rules)
367371
if refimported:
368-
main, modmap = _stash_modules(original_main)
372+
main, modmap = _stash_modules(main, original_main)
373+
369374
with _open(filename, 'wb', seekable=True) as file:
370375
pickler = Pickler(file, protocol, **kwds)
371376
pickler._main = main #FIXME: dill.settings are disabled

dill/tests/test_session.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ def test_runtime_module():
201201
runtime_mod = ModuleType(modname)
202202
runtime_mod.x = 42
203203

204-
mod, _ = dill.session._stash_modules(runtime_mod)
204+
mod, _ = dill.session._stash_modules(runtime_mod, runtime_mod)
205205
if mod is not runtime_mod:
206206
print("There are objects to save by referenece that shouldn't be:",
207207
mod.__dill_imported, mod.__dill_imported_as, mod.__dill_imported_top_level,

0 commit comments

Comments
 (0)