[issue42873] Exponential time and space requirements for compilation of nested try/finally blocks

Mark Dickinson report at bugs.python.org
Sat Jan 9 07:19:47 EST 2021


Mark Dickinson <dickinsm at gmail.com> added the comment:

For extra fun, you can add `break` and `continue` paths into the mix to get a 5-fold instead of 3-fold  code size increase per level of nesting. It's still contrived code, though.

Example where do_cleanup() ends up with 5**4 = 625 paths:

----

def f():
    while True:
        try:
            if something(): break
            elif something_else(): continue
            elif yet_something_else(): return
        finally:
            try:
                if something(): break
                elif something_else(): continue
                elif yet_something_else(): return
            finally:
                try:
                    if something(): break
                    elif something_else(): continue
                    elif yet_something_else(): return
                finally:
                    try:
                        if something(): break
                        elif something_else(): continue
                        elif yet_something_else(): return
                    finally:
                        do_cleanup()
----

----------

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue42873>
_______________________________________


More information about the Python-bugs-list mailing list