Skip to content
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

Remove non-standard __transient__ support #110

Merged
merged 1 commit into from
Jul 25, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 1 addition & 21 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -627,8 +627,7 @@ def save_instancemethod(self, obj):
dispatch[types.MethodType] = save_instancemethod

def save_inst(self, obj):
"""Inner logic to save instance. Based off pickle.save_inst
Supports __transient__"""
"""Inner logic to save instance. Based off pickle.save_inst"""
cls = obj.__class__

# Try the dispatch table (pickle module doesn't do it)
Expand Down Expand Up @@ -666,13 +665,6 @@ def save_inst(self, obj):
getstate = obj.__getstate__
except AttributeError:
stuff = obj.__dict__
#remove items if transient
if hasattr(obj, '__transient__'):
transient = obj.__transient__
stuff = stuff.copy()
for k in list(stuff.keys()):
if k in transient:
del stuff[k]
else:
stuff = getstate()
pickle._keep_alive(stuff, memo)
Expand Down Expand Up @@ -735,8 +727,6 @@ def __getattribute__(self, item):

def save_reduce(self, func, args, state=None,
listitems=None, dictitems=None, obj=None):
"""Modified to support __transient__ on new objects
Change only affects protocol level 2 (which is always used by PiCloud"""
# Assert that args is a tuple or None
if not isinstance(args, tuple):
raise pickle.PicklingError("args from reduce() should be a tuple")
Expand All @@ -750,7 +740,6 @@ def save_reduce(self, func, args, state=None,

# Protocol 2 special case: if func's name is __newobj__, use NEWOBJ
if self.proto >= 2 and getattr(func, "__name__", "") == "__newobj__":
#Added fix to allow transient
cls = args[0]
if not hasattr(cls, "__new__"):
raise pickle.PicklingError(
Expand All @@ -761,15 +750,6 @@ def save_reduce(self, func, args, state=None,
args = args[1:]
save(cls)

#Don't pickle transient entries
if hasattr(obj, '__transient__'):
transient = obj.__transient__
state = state.copy()

for k in list(state.keys()):
if k in transient:
del state[k]

save(args)
write(pickle.NEWOBJ)
else:
Expand Down