Skip to main content

Function decorator that ensures that no global and no nonlocal variables are used, making Jupyter notebooks much safer

Project description

no_global_nonlocal_vars

Function decorator that ensures that no global and no nonlocal variables are used, making Jupyter notebooks much safer

Installing

Install:

pip install no_global_nonlocal_vars

Usage

# Correct Output
@no_global_nonlocal_vars
def test_no_global_nonlocal_vars_GOOD(x, repeat):
    return np.array([x] * repeat)


# Error from typo
@no_global_nonlocal_vars
def test_no_global_nonlocal_vars_typo_GOOD(x_typo, repeat_typo):
    return np.array([x] * repeat)


# Nested function works
@no_global_nonlocal_vars
def test_no_global_nonlocal_vars_nested_GOOD(x, repeat=10):

    @no_global_nonlocal_vars
    def helper(x, repeat):
        return np.array([x] * repeat)

    return helper(x, repeat)


# Error from nonlocal variable typo
@no_global_nonlocal_vars
def test_no_global_nonlocal_vars_nested_typo_GOOD(x, repeat=10):

    @no_global_nonlocal_vars
    def helper(x_typo, repeat_typo):
        return np.array([x] * repeat)

    return helper(x, repeat)

Notes

  • The errors show up only upon first time running the function, not at function definition time

Related Work

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

no_global_nonlocal_vars-0.0.2.tar.gz (3.2 kB view hashes)

Uploaded Source

Built Distribution

no_global_nonlocal_vars-0.0.2-py3-none-any.whl (3.5 kB view hashes)

Uploaded Python 3

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page