Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change script so it generates a chain of functions instead #1

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

seddonym
Copy link
Contributor

@seddonym seddonym commented Jan 2, 2025

This is just a quick experiment and shouldn't be merged.

The command uv run generate.py --chain-length=3 --recursion-limit=1000 will generate a module that looks like this:

import sys

sys.setrecursionlimit(1000)

print(f"Calling a chain of 3 functions with a recursion limit of 1000...")


def function_001():
    function_002()


def function_002():
    function_003()


def function_003():
    print("Got to the end of the call chain.")


if __name__ == "__main__":
    function_001()

Results

Unlike with import chains, each additional function call requires the recursion limit to be raised by 1:

E.g. with a recursion limit of 1000:

  File ".../import-recursion-demo/src/funcdemo.py", line 4001, in function_999
    function_1000()
RecursionError: maximum recursion depth exceeded

This is just a quick experiment and shouldn't be merged.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant