Skip to main content

A simple package to extract inner functions from an outer function

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

extract_inner_function-0.0.1.tar.gz (2.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

extract_inner_function-0.0.1-py3-none-any.whl (2.7 kB view details)

Uploaded Python 3

File details

Details for the file extract_inner_function-0.0.1.tar.gz.

File metadata

  • Download URL: extract_inner_function-0.0.1.tar.gz
  • Upload date:
  • Size: 2.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.12.3

File hashes

Hashes for extract_inner_function-0.0.1.tar.gz
Algorithm Hash digest
SHA256 dc6c33f60a2473510b984c15d63052f5cd99f7ee080a30d5a726b62eb6308180
MD5 da14d52ed7fffe272eabd6e89d541c15
BLAKE2b-256 271ca81557f04ad989d018b88a6270570cbaf5a6c19e60656ff3f60f7a9f6711

See more details on using hashes here.

File details

Details for the file extract_inner_function-0.0.1-py3-none-any.whl.

File metadata

File hashes

Hashes for extract_inner_function-0.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 43dc134453515636cc408912537c3eddfd379752b9db75e5450ea2af9f62258d
MD5 2c0ea75c62da4de650c9ad8c43e8ec84
BLAKE2b-256 169b06420778a56921970e791d74d077d263961a88b551239dee46b1aada12c3

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page