Skip to content

Commit c05c7bd

Browse files
ogriselrgbkrk
authored andcommitted
Fix interactive function pickling
1 parent 98855d2 commit c05c7bd

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

cloudpickle/cloudpickle.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -621,11 +621,15 @@ def save_global(self, obj, name=None, pack=struct.pack):
621621
dispatched here.
622622
"""
623623
try:
624-
return Pickler.save_global(self, obj, name=name)
624+
if obj.__module__ == "__main__":
625+
raise ValueError("%r is defined in __main__" % obj)
626+
else:
627+
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)