Skip to content

Commit

Permalink
backport of cloudpipe/cloudpickle#132, [MRG] Regression on pickling c…
Browse files Browse the repository at this point in the history
…lasses from the __main__ module
  • Loading branch information
BryanCutler committed Jan 29, 2018
1 parent c362df8 commit e7eabe3
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion python/pyspark/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,12 +620,16 @@ def save_global(self, obj, name=None, pack=struct.pack):
The name of this method is somewhat misleading: all types get
dispatched here.
"""
if obj.__module__ == "__main__":
return self.save_dynamic_class(obj)

try:
return Pickler.save_global(self, obj, name=name)
except Exception:
if obj.__module__ == "__builtin__" or obj.__module__ == "builtins":
if obj in _BUILTIN_TYPE_NAMES:
return self.save_reduce(_builtin_type, (_BUILTIN_TYPE_NAMES[obj],), obj=obj)
return self.save_reduce(
_builtin_type, (_BUILTIN_TYPE_NAMES[obj],), obj=obj)

typ = type(obj)
if typ is not obj and isinstance(obj, (type, types.ClassType)):
Expand Down

0 comments on commit e7eabe3

Please sign in to comment.