Meta icon indicating copy to clipboard operation
Meta copied to clipboard

Fix `return` in `except`

Open kichik opened this issue 12 years ago • 1 comments

The following code tries to return a value from an except block but fails with an assertion.

import meta

def f(x):
    try:
        return x
    except:
        return x + 1  # <== offender

f_ast = meta.decompiler.decompile_func(f)
meta.asttools.print_ast(f_ast)
print meta.dump_python_source(f_ast)

It results in the following assertion:

AssertionError:              21 RETURN_VALUE

The suggested patch simply adds support for return and seems to work. It results in valid AST.

kichik avatar Oct 15 '13 17:10 kichik

Hi @srossross any chance of merging this ?

stuaxo avatar Feb 07 '21 21:02 stuaxo