extract_inner_function
A simple package to extract inner functions in Python
Context
Normally, inner functions are accessible only inside the function itself, and we cannot do this
def outer():
def inner1(a, b):
# this can be accessed only inside of outer()
But there is actually a (hacky) way to extract inner functions
Disclaimer - this package is for fun. Try not to use in prod
installation
pip install extract_inner_function
quickstart
def outer():
def inner1():
print("from inner1")
def inner2(a, b):
print("from inner2", a, b)
def inner3(*args, **kwargs):
print(f"{args=} {kwargs=}")
print("from outer")
from extract_inner_function import extract_inner_function
func = extract_inner_function(
outer_func=outer,
inner_func_name="inner3",
print_inner_func=True,
)
func(1, 2, a=6, b=7)
# def inner3(*args, **kwargs):
# print(f"{args=} {kwargs=}")
# args=(1, 2) kwargs={'a': 6, 'b': 7}
^ notice that we are able to extract the inner function here
so when should we use this package?
- if the existing codebase contains lots of inner functinos
- you wish to do unit testing on these inner functions
- you don't have time to (or cannot be bothered to) refactor the codebase
Release files for extract-inner-function 0.0.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| extract_inner_function-0.0.1.tar.gz | 2.7 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| extract_inner_function-0.0.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 5.5 kB
Release files / extract_inner_function-0.0.1.tar.gz
| Download URL | extract_inner_function-0.0.1.tar.gz |
|---|---|
| Size | 2.7 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
dc6c33f60a2473510b984c15d63052f5cd99f7ee080a30d5a726b62eb6308180
|
|
BLAKE2b-256 checksum How to use checksums |
271ca81557f04ad989d018b88a6270570cbaf5a6c19e60656ff3f60f7a9f6711
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|
Release files / extract_inner_function-0.0.1-py3-none-any.whl
| Download URL | extract_inner_function-0.0.1-py3-none-any.whl |
|---|---|
| Size | 2.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
43dc134453515636cc408912537c3eddfd379752b9db75e5450ea2af9f62258d
|
|
BLAKE2b-256 checksum How to use checksums |
169b06420778a56921970e791d74d077d263961a88b551239dee46b1aada12c3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.0.1 CPython/3.12.3
|