How to use the dill.detect.globalvars function in dill

To help you get started, we’ve selected a few dill examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github uqfoundation / dill / tests / test_detect.py View on Github external
b
            def h():
                c
    assert globalvars(f) == dict(a=1, b=2, c=3)

    res = globalvars(foo, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(foo, recurse=False)
    assert res == {}
    zap = foo(2)
    res = globalvars(zap, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(zap, recurse=False)
    assert set(res) == set(['squared'])
    del zap
    res = globalvars(squared)
    assert set(res) == set(['a'])
    # FIXME: should find referenced __builtins__
github uqfoundation / dill / tests / test_detect.py View on Github external
def test_globals():
    def f():
        a
        def g():
            b
            def h():
                c
    assert globalvars(f) == dict(a=1, b=2, c=3)

    res = globalvars(foo, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(foo, recurse=False)
    assert res == {}
    zap = foo(2)
    res = globalvars(zap, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(zap, recurse=False)
    assert set(res) == set(['squared'])
    del zap
    res = globalvars(squared)
    assert set(res) == set(['a'])
    # FIXME: should find referenced __builtins__
github uqfoundation / dill / tests / test_detect.py View on Github external
def test_globals():
    def f():
        a
        def g():
            b
            def h():
                c
    assert globalvars(f) == dict(a=1, b=2, c=3)

    res = globalvars(foo, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(foo, recurse=False)
    assert res == {}
    zap = foo(2)
    res = globalvars(zap, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(zap, recurse=False)
    assert set(res) == set(['squared'])
    del zap
    res = globalvars(squared)
    assert set(res) == set(['a'])
    # FIXME: should find referenced __builtins__
github uqfoundation / dill / tests / test_detect.py View on Github external
def test_globals():
    def f():
        a
        def g():
            b
            def h():
                c
    assert globalvars(f) == dict(a=1, b=2, c=3)

    res = globalvars(foo, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(foo, recurse=False)
    assert res == {}
    zap = foo(2)
    res = globalvars(zap, recurse=True)
    assert set(res) == set(['squared', 'a'])
    res = globalvars(zap, recurse=False)
    assert set(res) == set(['squared'])
    del zap
    res = globalvars(squared)
    assert set(res) == set(['a'])
    # FIXME: should find referenced __builtins__
github uqfoundation / dill / tests / test_detect.py View on Github external
def test_lambdify():
    try:
        from sympy import symbols, lambdify
    except ImportError:
        return
    settings['recurse'] = True
    x = symbols("x")
    y = x**2
    f = lambdify([x], y)
    z = min
    d = globals()
    globalvars(f, recurse=True, builtin=True)
    assert z is min 
    assert d is globals()
github Meeshkan / meeshkan-client / meeshkan / api / utils.py View on Github external
def _write_globals(func, path: Path) -> Path:
    """Fetches, serialized and writes current globals required for `func` to `path`.

    :param func: A callable that may or may not use global variables
    :param path: Where to write the serialized globals
    :return Path object to the serialized globals file
    """
    globs = globalvars(func)  # Globals that are relevant for the function to run
    globs.update({'__name__': '__main__'})  # Include the entry point for the script
    globs_serialized = Serializer.serialize(globs)
    globs_file = path.joinpath("globs.msk")
    with globs_file.open('w') as globs_fd:
        globs_fd.write(globs_serialized)
        globs_fd.flush()
    return globs_file