Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/bswck/injection
The ultimate replacement for proxies in Python.
https://github.com/bswck/injection
Last synced: 24 days ago
JSON representation
The ultimate replacement for proxies in Python.
- Host: GitHub
- URL: https://github.com/bswck/injection
- Owner: bswck
- Created: 2024-07-27T01:18:49.000Z (3 months ago)
- Default Branch: main
- Last Pushed: 2024-07-31T08:43:09.000Z (3 months ago)
- Last Synced: 2024-08-01T06:31:40.770Z (3 months ago)
- Language: Python
- Homepage:
- Size: 31.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# injection
The ultimate replacement for proxies.## Example
```py
def factory(scope):
return "hello"# if once is True, the factory is called once and the injected object is reused in every child scope.
# once doesnt matter for global scope setting which makes the injection
# object unretrievable after first reference (the given variable names are assigned the injected object
# and the injection object gets freed)
var = injection("var", factory=factory, into=locals(), once=True)def func():
# on first 'var' expression f_locals['var'] = factory(f_locals) is triggered
print(var, type(var))print(var) # prints the injection object because of scope="local" (this is global scope)
func()
```
outputs
```hello
```