nested
Extract your nested functions!
Installation
pip install nestd
Usage
from nestd import nested, get_all_nested
def dummy_function():
test_variable = "hello, world"
def inner_function():
nonlocal test_variable
return test_variable
def dummy_function_with_two_inner_functions():
test_variable = "hello, world"
test_array = [1, 2, 3]
def inner_function():
nonlocal test_variable
return test_variable
def inner_function_2():
nonlocal test_array
return test_array[1:]
def test_nested_function():
inner_function = nested(dummy_function, "inner_function", test_variable="hello" )
assert "hello" == inner_function()
def test_2_nested_functions():
all_inner_functions = get_all_nested(dummy_function_with_two_inner_functions, "hello_world", [1,2])
inner_function, inner_function_2 = all_inner_functions
assert inner_function[0] == "inner_function"
assert inner_function[1]() == "hello_world"
assert inner_function_2[0] == "inner_function_2"
assert inner_function_2[1]() == [2]
To perform a very deep nested search
def dummy_function_with_nested_inner_functions():
test_array = [1, 2, 3]
def math():
nonlocal test_array
def sum():
nonlocal test_array
def sum_of_array():
nonlocal test_array
inside_arr = [random.randint(1, 10)] * len(test_array)
return test_array + inside_arr
def multi_of_array():
nonlocal test_array
inside_arr = [random.randint(1, 10)] * len(test_array)
for i in range(len(test_array)):
inside_arr[i] = inside_arr[i] * test_array[i]
return inside_arr
ans = 0
for i in test_array:
ans += i
return ans
def multiply():
nonlocal test_array
ans = 1
for i in test_array:
ans = ans * i
return ans
return test_array
def stats():
nonlocal test_array
def mean():
nonlocal test_array
return sum(test_array) / len(test_array)
return test_array
def test_3_nested_functions():
inner_functions = get_all_deep_nested(
dummy_function_with_nested_inner_functions,
test_array=[1, 2, 3],
)
assert inner_functions["math"]() == [1, 2, 3]
assert inner_functions["sum"]() == 6
assert inner_functions["mean"]() == 2.0
Contributor Guidelines
Feel free to open an issue for any clarification or for any suggestions.
To Develop Locally
poetry installto install the dependenciespytest teststo run the tests
Metadata
Release files for nestd 0.3.2
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| nestd-0.3.2.tar.gz | 3.3 kB | Without provenance | Details for nestd-0.3.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| nestd-0.3.2-py3-none-any.whl | Python 3 | none | any | Details for nestd-0.3.2-py3-none-any.whl |
Total release size: 6.2 kB
Release files / nestd-0.3.2.tar.gz
| Download URL | nestd-0.3.2.tar.gz |
|---|---|
| Size | 3.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
111e59a7d86bebe903d736a1c7a652c1e75a1c31d5b8aae3b416b7cb2e5ba8e5
|
|
BLAKE2b-256 checksum How to use checksums |
09b6a23ca291cbd2695c59c0df5defb39ecc2b717168f025347b60c3f470b44c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.7 Darwin/21.6.0
|
Release files / nestd-0.3.2-py3-none-any.whl
| Download URL | nestd-0.3.2-py3-none-any.whl |
|---|---|
| Size | 3.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
efecca80d5780495f178bbbb9af2e6a54f115f47beb7a9e19c1bfd03a0341a39
|
|
BLAKE2b-256 checksum How to use checksums |
08c1af9e8e04ac9bcc67b8cb1e906b3a93738d9a0fbbbbb99b3aa723368e8c96
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/1.2.2 CPython/3.10.7 Darwin/21.6.0
|
Security for nestd 0.3.2
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.