https://github.com/havakv/safescope
Prevent access to global variables in functions
Science Score: 10.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
○codemeta.json file
-
○.zenodo.json file
-
○DOI references
-
○Academic publication links
-
✓Committers with academic emails
1 of 4 committers (25.0%) from academic institutions -
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (11.3%) to scientific vocabulary
Keywords
Keywords from Contributors
Repository
Prevent access to global variables in functions
Basic Info
Statistics
- Stars: 4
- Watchers: 1
- Forks: 0
- Open Issues: 3
- Releases: 0
Topics
Metadata Files
README.md
safescope
safescope is a small python package useful for development in jupyter notebooks.
The goal is to prevent functions from using global variables and instead raise a NameError.
This is achieved by mimicking a module, and define all functions in that module (named side_scope).
Example
The main part of safescope is the decorator @safescope. This mimics writing the function in a file side_scope.py and importing this function to the notebook. Hence, functions decorated with @safescope will not have access to variables declared in the notebook environment.
In the example below, only foo(1) will execute, as bar(1) returns a NameError.
```python
from safescope import safescope
x = 9
def foo(y): return x + y
@safescope def bar(y): return x + y
foo(1) # Returns 10 bar(1) # Raise "NameError: name 'x' is not defined" ```
By using Imports, the imports are added to both the main scope and the side_scope, making them available for the functions decorated with @safescope.
```python
from safescope import safescope, Imports
with Imports(): import numpy as np
@safescope def arange(n): return np.arange(n)
arange(4) # Returns array([0, 1, 2, 3]) ```
Installation
safescope can either be installed from pypi with pip/pip3:
bash
pip install safescope
or from github with:
bash
pip install git+git://github.com/havakv/safescope.git
or from source by cloning the repo:
bash
git clone https://github.com/havakv/safescope.git
cd safescope
python setup.py install
Owner
- Name: Haavard Kvamme
- Login: havakv
- Kind: user
- Company: University of Oslo
- Repositories: 19
- Profile: https://github.com/havakv
GitHub Events
Total
Last Year
Committers
Last synced: 9 months ago
Top Committers
| Name | Commits | |
|---|---|---|
| havakv | h****e@g****m | 28 |
| Havard | h****d@H****l | 20 |
| Havard | h****d@h****u | 6 |
| Haavard Kvamme | h****e@g****m | 3 |
Committer Domains (Top 20 + Academic)
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 4
- Total pull requests: 0
- Average time to close issues: 14 days
- Average time to close pull requests: N/A
- Total issue authors: 1
- Total pull request authors: 0
- Average comments per issue: 0.5
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 0
- Average time to close issues: N/A
- Average time to close pull requests: N/A
- Issue authors: 0
- Pull request authors: 0
- Average comments per issue: 0
- Average comments per pull request: 0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
- havakv (4)
Pull Request Authors
Top Labels
Issue Labels
Pull Request Labels
Packages
- Total packages: 1
-
Total downloads:
- pypi 18 last-month
- Total dependent packages: 0
- Total dependent repositories: 1
- Total versions: 11
- Total maintainers: 1
pypi.org: safescope
Python package for preventing use of variables from global scope.
- Homepage: https://github.com/havakv/safescope
- Documentation: https://safescope.readthedocs.io/
- License: BSD license
-
Latest release: 0.2.6
published over 6 years ago