def _check_dyn_class(Klass, saved): def check(): if Klass.classvar != 100: raise AssertionError("Check failed. Klass reset.") check() loaded = loads(saved) if loaded is not Klass: raise AssertionError("Expected reuse") # Without the patch, each `loads(saved)` will reset `Klass.classvar` check() loaded = loads(saved) if loaded is not Klass: raise AssertionError("Expected reuse") check()
def check_unpickle_dyn_class_new_proc(saved): Klass = loads(saved) assert Klass.classvar != 100 # mutate Klass.classvar = 100 # check _check_dyn_class(Klass, saved)
def test_dynamic_class_reset_on_unpickle(self): # a dynamic class class Klass: classvar = None def mutator(): Klass.classvar = 100 def check(): self.assertEqual(Klass.classvar, 100) saved = dumps(Klass) mutator() check() loads(saved) # Without the patch, each `loads(saved)` will reset `Klass.classvar` check() loads(saved) check()
def _numba_unpickle(address, bytedata, hashed): """Used by `numba_unpickle` from _helperlib.c Parameters ---------- address : int bytedata : bytes hashed : bytes Returns ------- obj : object unpickled object """ key = (address, hashed) try: obj = _unpickled_memo[key] except KeyError: _unpickled_memo[key] = obj = cloudpickle.loads(bytedata) return obj