Skip to content

Commit

Permalink
Fix test some test failures caused by dill.memorise
Browse files Browse the repository at this point in the history
  • Loading branch information
matsjoyce committed Jun 12, 2014
1 parent 72dacaf commit 5ea2d6d
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 14 deletions.
26 changes: 15 additions & 11 deletions dill/dill.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ class Pickler(StockPickler):
def __init__(self, *args, **kwargs):
StockPickler.__init__(self, *args, **kwargs)
self._main_module = _main_module
self._dill_memorise_cashe = {}
self._memorise_cashe = {}

class Unpickler(StockUnpickler):
"""python's Unpickler extended to interpreter sessions and more types"""
Expand Down Expand Up @@ -798,16 +798,20 @@ def save_weakproxy(pickler, obj):

@register(ModuleType)
def save_module(pickler, obj):
try:
changed = memorise.whats_changed(obj,
seen=pickler._dill_memorise_cashe)[0]
except RuntimeError: # not memorised module, probably part of dill
log.info("M2: %s" % obj)
pickler.save_reduce(_import_module, (obj.__name__,), obj=obj)
else:
log.info("M1: %s" % obj)
pickler.save_reduce(_import_module, (obj.__name__,), obj=obj,
state=changed)
if obj.__name__ != "dill":
try:
changed = memorise.whats_changed(obj,
seen=pickler._memorise_cashe)[0]
except RuntimeError: # not memorised module, probably part of dill
pass
else:
log.info("M1: %s" % obj)
pickler.save_reduce(_import_module, (obj.__name__,), obj=obj,
state=changed)
return

log.info("M2: %s" % obj)
pickler.save_reduce(_import_module, (obj.__name__,), obj=obj)
return

@register(TypeType)
Expand Down
12 changes: 9 additions & 3 deletions dill/memorise.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,10 @@ def get_attrs(obj):
if type(obj) in builtins_types \
or type(obj) is type and obj in builtins_types:
return None
return obj.__dict__ if hasattr(obj, "__dict__") else None
try:
return obj.__dict__ if hasattr(obj, "__dict__") else None
except:
return None


def get_seq(obj, cashe={str: False, frozenset: False, list: True, set: True,
Expand Down Expand Up @@ -71,8 +74,11 @@ def get_attrs_id(obj):
if type(obj) in builtins_types \
or type(obj) is type and obj in builtins_types:
return None
return {key: id(value) for key, value in obj.__dict__.items()} \
if hasattr(obj, "__dict__") else None
try:
return {key: id(value) for key, value in obj.__dict__.items()} \
if hasattr(obj, "__dict__") else None
except:
return None


def get_seq_id(obj, done=None):
Expand Down

0 comments on commit 5ea2d6d

Please sign in to comment.