Skip to content

Commit

Permalink
ENH move override_existing_globals to state
Browse files Browse the repository at this point in the history
  • Loading branch information
pierreglaser committed Nov 15, 2018
1 parent 602a629 commit 9976e1e
Showing 1 changed file with 2 additions and 7 deletions.
9 changes: 2 additions & 7 deletions cloudpickle/cloudpickle.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,13 @@ def save_function_tuple(self, func):
'module': func.__module__,
'name': func.__name__,
'doc': func.__doc__,
'override_existing_globals': self.override_existing_globals
}
if hasattr(func, '__annotations__') and sys.version_info >= (3, 7):
state['annotations'] = func.__annotations__
if hasattr(func, '__qualname__'):
state['qualname'] = func.__qualname__
save(state)
save(self.override_existing_globals)
write(pickle.TUPLE)
write(pickle.REDUCE) # applies _fill_function on the tuple

Expand Down Expand Up @@ -1058,14 +1058,9 @@ def _fill_function(*args):
The skeleton itself is create by _make_skel_func().
"""
override_existing_globals = True
if len(args) == 2:
func = args[0]
state = args[1]
elif len(args) == 3:
func = args[0]
state = args[1]
override_existing_globals = args[2]
elif len(args) == 5:
# Backwards compat for cloudpickle v0.4.0, after which the `module`
# argument was introduced
Expand All @@ -1083,7 +1078,7 @@ def _fill_function(*args):

# This updates the variables of func's module using func's globals from the
# time at which it was pickled.
if override_existing_globals:
if state.get('override_existing_globals', True):
func.__globals__.update(state['globals'])
else:
for k, v in state['globals'].items():
Expand Down

0 comments on commit 9976e1e

Please sign in to comment.