Exemplo n.º 1
0
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()
Exemplo n.º 2
0
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)
Exemplo n.º 3
0
    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()
Exemplo n.º 4
0
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