<picture>
<source media="(prefers-color-scheme: dark)" srcset="https://raw.githubusercontent.com/jeertmans/varscope/main/static/logo_dark_transparent.png">
<source media="(prefers-color-scheme: light)" srcset="https://raw.githubusercontent.com/jeertmans/varscope/main/static/logo_light_transparent.png">
<img alt="VarScope Logo" height="256px" align="right" src="https://raw.githubusercontent.com/jeertmans/varscope/main/static/logo.png">
</picture>
# VarScope
[![Documentation][documentation-badge]][documentation-url]
[![codecov][codecov-badge]][codecov-url]
Ultra simple module for creating local scopes in Python.
## Installation
VarScope can be installed with `pip`:
```bash
pip install varscope
```
## Usage
```python
>>> from varscope import scope
>>>
>>> a = 1
>>> with scope(): # Everything defined after will only apply inside the scope
... a = 2
... b = 3
...
>>> a
1
>>> b # Not defined, because outside of scope
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'b' is not defined
>>>
>>> with scope() as s: # We can choose to keep some variables
... a = 2
... b = 3
... s.keep("b")
...
>>> b
3
>>> with scope("a"): # We can also move variables inside scope
... a = 2
...
>>> a # Not defined, because outside of scope
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'a' is not defined
>>>
>>> d = {}
>>> with scope(): # Scope can mutate object from outside
... d["a"] = 1
...
>>> d["a"]
1
```
[documentation-badge]: https://img.shields.io/website?down_color=lightgrey&down_message=offline&label=documentation&up_color=green&up_message=online&url=https%3A%2F%2Feertmans.be%2Fvarscope%2F
[documentation-url]: https://eertmans.be/varscope/
[codecov-badge]: https://codecov.io/gh/jeertmans/varscope/branch/main/graph/badge.svg?token=1dJ1AKWMR5
[codecov-url]: https://codecov.io/gh/jeertmans/varscope
Raw data
{
"_id": null,
"home_page": "https://github.com/jeertmans/varscope",
"name": "varscope",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.8,<4.0",
"maintainer_email": "",
"keywords": "scope,python",
"author": "J\u00e9rome Eertmans",
"author_email": "jeertmans@icloud.com",
"download_url": "https://files.pythonhosted.org/packages/59/8b/0610f3f1012addec72d752e22a0e3b8f6222d03d0b9181fce0c573e409f2/varscope-0.1.1.tar.gz",
"platform": null,
"description": "<picture>\n <source media=\"(prefers-color-scheme: dark)\" srcset=\"https://raw.githubusercontent.com/jeertmans/varscope/main/static/logo_dark_transparent.png\">\n <source media=\"(prefers-color-scheme: light)\" srcset=\"https://raw.githubusercontent.com/jeertmans/varscope/main/static/logo_light_transparent.png\">\n <img alt=\"VarScope Logo\" height=\"256px\" align=\"right\" src=\"https://raw.githubusercontent.com/jeertmans/varscope/main/static/logo.png\">\n</picture>\n\n# VarScope\n\n[![Documentation][documentation-badge]][documentation-url]\n[![codecov][codecov-badge]][codecov-url]\n\nUltra simple module for creating local scopes in Python.\n\n## Installation\n\nVarScope can be installed with `pip`:\n\n```bash\npip install varscope\n```\n\n## Usage\n\n```python\n>>> from varscope import scope\n>>>\n>>> a = 1\n>>> with scope(): # Everything defined after will only apply inside the scope\n... a = 2\n... b = 3\n...\n>>> a\n1\n>>> b # Not defined, because outside of scope\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nNameError: name 'b' is not defined\n>>>\n>>> with scope() as s: # We can choose to keep some variables\n... a = 2\n... b = 3\n... s.keep(\"b\")\n...\n>>> b\n3\n>>> with scope(\"a\"): # We can also move variables inside scope\n... a = 2\n...\n>>> a # Not defined, because outside of scope\nTraceback (most recent call last):\n File \"<stdin>\", line 1, in <module>\nNameError: name 'a' is not defined\n>>>\n>>> d = {}\n>>> with scope(): # Scope can mutate object from outside\n... d[\"a\"] = 1\n...\n>>> d[\"a\"]\n1\n```\n\n[documentation-badge]: https://img.shields.io/website?down_color=lightgrey&down_message=offline&label=documentation&up_color=green&up_message=online&url=https%3A%2F%2Feertmans.be%2Fvarscope%2F\n[documentation-url]: https://eertmans.be/varscope/\n[codecov-badge]: https://codecov.io/gh/jeertmans/varscope/branch/main/graph/badge.svg?token=1dJ1AKWMR5\n[codecov-url]: https://codecov.io/gh/jeertmans/varscope\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Ultra simple module for creating local scopes in Python",
"version": "0.1.1",
"project_urls": {
"Documentation": "https://eertmans.be/varscope",
"Homepage": "https://github.com/jeertmans/varscope",
"Repository": "https://github.com/jeertmans/varscope"
},
"split_keywords": [
"scope",
"python"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "36c10a87217f6fd3fb54381e58ae9aa158cad72559a98365e569ce182d3e52d9",
"md5": "d21605aaf2213a7d2adc996b8af1cebe",
"sha256": "5e02fea1ec9d030834913aa2805b39d415239a0a899e7d10ba290075d236854d"
},
"downloads": -1,
"filename": "varscope-0.1.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d21605aaf2213a7d2adc996b8af1cebe",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.8,<4.0",
"size": 4074,
"upload_time": "2023-08-11T20:53:42",
"upload_time_iso_8601": "2023-08-11T20:53:42.145397Z",
"url": "https://files.pythonhosted.org/packages/36/c1/0a87217f6fd3fb54381e58ae9aa158cad72559a98365e569ce182d3e52d9/varscope-0.1.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "598b0610f3f1012addec72d752e22a0e3b8f6222d03d0b9181fce0c573e409f2",
"md5": "6428275c97c96cddc1bbf39115e3fd93",
"sha256": "12bb03e38506f45e1952bba03e622cf08835548fd8fd2734e1026c7e0ee3ab9d"
},
"downloads": -1,
"filename": "varscope-0.1.1.tar.gz",
"has_sig": false,
"md5_digest": "6428275c97c96cddc1bbf39115e3fd93",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.8,<4.0",
"size": 3806,
"upload_time": "2023-08-11T20:53:43",
"upload_time_iso_8601": "2023-08-11T20:53:43.089890Z",
"url": "https://files.pythonhosted.org/packages/59/8b/0610f3f1012addec72d752e22a0e3b8f6222d03d0b9181fce0c573e409f2/varscope-0.1.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-08-11 20:53:43",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "jeertmans",
"github_project": "varscope",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "varscope"
}