Skip to content

Commit e7eabe3

Browse files
committed
backport of cloudpipe/cloudpickle#132, [MRG] Regression on pickling classes from the __main__ module
1 parent c362df8 commit e7eabe3

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

python/pyspark/cloudpickle.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -620,12 +620,16 @@ def save_global(self, obj, name=None, pack=struct.pack):
620620
The name of this method is somewhat misleading: all types get
621621
dispatched here.
622622
"""
623+
if obj.__module__ == "__main__":
624+
return self.save_dynamic_class(obj)
625+
623626
try:
624627
return Pickler.save_global(self, obj, name=name)
625628
except Exception:
626629
if obj.__module__ == "__builtin__" or obj.__module__ == "builtins":
627630
if obj in _BUILTIN_TYPE_NAMES:
628-
return self.save_reduce(_builtin_type, (_BUILTIN_TYPE_NAMES[obj],), obj=obj)
631+
return self.save_reduce(
632+
_builtin_type, (_BUILTIN_TYPE_NAMES[obj],), obj=obj)
629633

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

0 commit comments

Comments
 (0)