MCPcopy Index your code
hub / github.com/cloudpipe/cloudpickle / _function_getnewargs

Method _function_getnewargs

cloudpickle/cloudpickle.py:1278–1309  ·  view source on GitHub ↗
(self, func)

Source from the content-addressed store, hash-verified

1276 return self._dynamic_function_reduce(obj)
1277
1278 def _function_getnewargs(self, func):
1279 code = func.__code__
1280
1281 # base_globals represents the future global namespace of func at
1282 # unpickling time. Looking it up and storing it in
1283 # cloudpickle.Pickler.globals_ref allow functions sharing the same
1284 # globals at pickling time to also share them once unpickled, at one
1285 # condition: since globals_ref is an attribute of a cloudpickle.Pickler
1286 # instance, and that a new cloudpickle.Pickler is created each time
1287 # cloudpickle.dump or cloudpickle.dumps is called, functions also need
1288 # to be saved within the same invocation of
1289 # cloudpickle.dump/cloudpickle.dumps (for example:
1290 # cloudpickle.dumps([f1, f2])). There is no such limitation when using
1291 # cloudpickle.Pickler.dump, as long as the multiple invocations are
1292 # bound to the same cloudpickle.Pickler instance.
1293 base_globals = self.globals_ref.setdefault(id(func.__globals__), {})
1294
1295 if base_globals == {}:
1296 # Add module attributes used to resolve relative imports
1297 # instructions inside func.
1298 for k in ["__package__", "__name__", "__path__", "__file__"]:
1299 if k in func.__globals__:
1300 base_globals[k] = func.__globals__[k]
1301
1302 # Do not bind the free variables before the function is created to
1303 # avoid infinite recursion.
1304 if func.__closure__ is None:
1305 closure = None
1306 else:
1307 closure = tuple(_make_empty_cell() for _ in range(len(code.co_freevars)))
1308
1309 return code, base_globals, None, None, closure
1310
1311 def dump(self, obj):
1312 try:

Callers 1

Calls 1

_make_empty_cellFunction · 0.85

Tested by

no test coverage detected