Simple library for patching function inner scope
Project description
Argumentize decorator allow convert any function into kind a 'pure' function that eliminate all globals and closures as a implicit dependencies but allow them to be passed as regular key-value arguments.
Here is a simple example:
from argumentize import argumentize
x = 100
def foo(a, b, c):
return a + b + c + x
foo = argumentize(foo)
foo(1, 2, 3) # 106
foo(1, 2, 3, x=10) # 16
Argumentized can be any dependency not only a variable. Here is how you can use it with a function:
from argumentize import argumentize
def foo(a, b, c):
return a + b + c
def bar(a, b, c, d):
return foo(a, b, c) + d
bar = argumentize(bar)
bar(1, 2, 3, 4) # 10
bar(1, 2, 3, 4, foo=lambda a, b, c: a * b * c) # 24
Argumentize can be used as a decorator:
from argumentize import argumentize
@argumentize
def foo(a, b, c):
return a + b + c
foo(1, 2, 3) # 6
foo(1, 2, 3, b=10) # 14
If you does not provide the value for argumented argument the default variable (either from globals or from the function closure) will be used
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file argumentize-1.0.2.tar.gz.
File metadata
- Download URL: argumentize-1.0.2.tar.gz
- Upload date:
- Size: 2.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d553f7236bdee2e47e79528f9aef15e61c606912fdf9f0782ea4e7393255b7dd
|
|
| MD5 |
21b6a1ce3e4c5a3ded079a87558b9fbc
|
|
| BLAKE2b-256 |
2e03ce287b00adb8d68fbff9f473498eec3987df89ea1ffbc2cbb4eed1371eb1
|
File details
Details for the file argumentize-1.0.2-py3-none-any.whl.
File metadata
- Download URL: argumentize-1.0.2-py3-none-any.whl
- Upload date:
- Size: 3.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.10.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
452535b74f756f7ebc06abbf9753c0c993ef69c424cfdb063c22715f7c240c7d
|
|
| MD5 |
305a306d5b6e1d690866b49528fea39e
|
|
| BLAKE2b-256 |
ed7fd3da190a2ee2434aa362ebd49766ce0a5d20a7082562e5c5ba3e92ddf192
|