Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bswck authored Nov 18, 2024
1 parent fa60f45 commit 6bb5166
Showing 1 changed file with 22 additions and 8 deletions.
30 changes: 22 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,13 +1,27 @@
# injection

Create Python variables on the fly.

> [!Note]
> This project is currently under a heavy rewrite,
> as the author learnt new ways of doing software during his existential crisis.
> He is now applying the new approach to provide the best quality libraries into your `site-packages/`.
> Consider sponsoring him [here](https://github.com/sponsors/bswck) to help him stop writing
> about himself in third person.
## How does that work?
_injection_ makes it possible to hook into variable name lookup via inserting a special key into scope dictionaries.

### Example
```py
from functools import partial
from random import randint

from injection import inject

roll: int
inject("roll", into=locals(), factory=partial(randint, 1, 6))

print(roll, type(roll) is int) # 6 True
print(roll, type(roll) is int) # 4 True
print(roll, type(roll) is int) # 3 True

# you never know what the value of roll will be!
```

It could be used for various purposes, for instance as a robust replacement for Flask's [local proxies](https://flask.palletsprojects.com/en/stable/reqcontext/#notes-on-proxies) or to implement pure-Python PEP 690
that would import things on first reference.

# Legal Info
© Copyright by Bartosz Sławecki ([@bswck](https://github.com/bswck)).
Expand Down

0 comments on commit 6bb5166

Please sign in to comment.