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 details)

Uploaded Source

Built Distribution

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

Uploaded Python 3

File details

Details for the file no_global_nonlocal_vars-0.0.2.tar.gz.

File metadata

File hashes

Hashes for no_global_nonlocal_vars-0.0.2.tar.gz
Algorithm Hash digest
SHA256 c2858700bfcb25f1e0eb1cd8e0b6ad9d49b6698529ce19e28df9388db0844eaa
MD5 3b736dce7f7087cefa0b1e4c984b9a42
BLAKE2b-256 60cc73df33e1e1bfe9ee2fdf2cf327e9755507da74771039197b2a0f256d195d

See more details on using hashes here.

File details

Details for the file no_global_nonlocal_vars-0.0.2-py3-none-any.whl.

File metadata

File hashes

Hashes for no_global_nonlocal_vars-0.0.2-py3-none-any.whl
Algorithm Hash digest
SHA256 d3789dafe87d095f95d5585e3fe846b0fee4961bc8e9245b52817799ac249b5e
MD5 e9020558273baf825474b7192e6c1856
BLAKE2b-256 ee2331e328abd80f000144626c7bd52aa4f5f805b823d7c92ee74798d63ec981

See more details on using hashes here.

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