| Name | nestd JSON |
| Version |
0.3.2
JSON |
| download |
| home_page | |
| Summary | A package to extract your nested functions! |
| upload_time | 2023-02-23 21:45:23 |
| maintainer | |
| docs_url | None |
| author | Sanskar Jethi |
| requires_python | >=3.8,<4.0 |
| license | |
| keywords |
|
| VCS |
|
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
# nested
Extract your nested functions!
## Installation
```python3
pip install nestd
```
## Usage
```python3
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
```python3
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
1. `poetry install` to install the dependencies
2. `pytest tests` to run the tests
Raw data
{
"_id": null,
"home_page": "",
"name": "nestd",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "",
"author": "Sanskar Jethi",
"author_email": "sansyrox@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/09/b6/a23ca291cbd2695c59c0df5defb39ecc2b717168f025347b60c3f470b44c/nestd-0.3.2.tar.gz",
"platform": null,
"description": "# nested\n\nExtract your nested functions!\n\n## Installation\n\n```python3\n pip install nestd\n```\n\n\n## Usage\n\n```python3\nfrom nestd import nested, get_all_nested\n\n\ndef dummy_function():\n test_variable = \"hello, world\"\n def inner_function():\n nonlocal test_variable\n return test_variable\n\n\ndef dummy_function_with_two_inner_functions():\n test_variable = \"hello, world\"\n test_array = [1, 2, 3]\n def inner_function():\n nonlocal test_variable\n return test_variable\n\n def inner_function_2():\n nonlocal test_array\n return test_array[1:]\n\n\ndef test_nested_function():\n inner_function = nested(dummy_function, \"inner_function\", test_variable=\"hello\" )\n assert \"hello\" == inner_function()\n\ndef test_2_nested_functions():\n all_inner_functions = get_all_nested(dummy_function_with_two_inner_functions, \"hello_world\", [1,2])\n inner_function, inner_function_2 = all_inner_functions\n\n assert inner_function[0] == \"inner_function\"\n assert inner_function[1]() == \"hello_world\"\n\n assert inner_function_2[0] == \"inner_function_2\"\n assert inner_function_2[1]() == [2]\n```\n\n\nTo perform a very deep nested search\n\n```python3\ndef dummy_function_with_nested_inner_functions():\n\n test_array = [1, 2, 3]\n\n def math():\n nonlocal test_array\n\n def sum():\n nonlocal test_array\n\n def sum_of_array():\n nonlocal test_array\n inside_arr = [random.randint(1, 10)] * len(test_array)\n return test_array + inside_arr\n\n def multi_of_array():\n nonlocal test_array\n inside_arr = [random.randint(1, 10)] * len(test_array)\n for i in range(len(test_array)):\n inside_arr[i] = inside_arr[i] * test_array[i]\n return inside_arr\n\n ans = 0\n for i in test_array:\n ans += i\n return ans\n\n def multiply():\n nonlocal test_array\n ans = 1\n for i in test_array:\n ans = ans * i\n\n return ans\n\n return test_array\n\n def stats():\n nonlocal test_array\n\n def mean():\n nonlocal test_array\n return sum(test_array) / len(test_array)\n\n return test_array\n\n\ndef test_3_nested_functions():\n inner_functions = get_all_deep_nested(\n dummy_function_with_nested_inner_functions,\n test_array=[1, 2, 3],\n )\n\n assert inner_functions[\"math\"]() == [1, 2, 3]\n assert inner_functions[\"sum\"]() == 6\n assert inner_functions[\"mean\"]() == 2.0\n\n```\n\n## Contributor Guidelines\n\nFeel free to open an issue for any clarification or for any suggestions.\n\n\n## To Develop Locally\n\n1. `poetry install` to install the dependencies\n2. `pytest tests` to run the tests\n",
"bugtrack_url": null,
"license": "",
"summary": "A package to extract your nested functions!",
"version": "0.3.2",
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "08c1af9e8e04ac9bcc67b8cb1e906b3a93738d9a0fbbbbb99b3aa723368e8c96",
"md5": "42b241521481054d99f750f9d5c5d865",
"sha256": "efecca80d5780495f178bbbb9af2e6a54f115f47beb7a9e19c1bfd03a0341a39"
},
"downloads": -1,
"filename": "nestd-0.3.2-py3-none-any.whl",
"has_sig": false,
"md5_digest": "42b241521481054d99f750f9d5c5d865",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 2956,
"upload_time": "2023-02-23T21:45:21",
"upload_time_iso_8601": "2023-02-23T21:45:21.567773Z",
"url": "https://files.pythonhosted.org/packages/08/c1/af9e8e04ac9bcc67b8cb1e906b3a93738d9a0fbbbbb99b3aa723368e8c96/nestd-0.3.2-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "09b6a23ca291cbd2695c59c0df5defb39ecc2b717168f025347b60c3f470b44c",
"md5": "26716ee3ebb26b080ff24a2aa0fada96",
"sha256": "111e59a7d86bebe903d736a1c7a652c1e75a1c31d5b8aae3b416b7cb2e5ba8e5"
},
"downloads": -1,
"filename": "nestd-0.3.2.tar.gz",
"has_sig": false,
"md5_digest": "26716ee3ebb26b080ff24a2aa0fada96",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 3251,
"upload_time": "2023-02-23T21:45:23",
"upload_time_iso_8601": "2023-02-23T21:45:23.268401Z",
"url": "https://files.pythonhosted.org/packages/09/b6/a23ca291cbd2695c59c0df5defb39ecc2b717168f025347b60c3f470b44c/nestd-0.3.2.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-02-23 21:45:23",
"github": false,
"gitlab": false,
"bitbucket": false,
"lcname": "nestd"
}