Skip to content

if cond: return val - bug in unparse #2

@gdraheim

Description

@gdraheim

During testing with python3.11 it showed a common bug:

  • when an if-statement is followed by a return statement ON THE SAME LINE
  • then the return statement moves to the end of the enclosing block of the if-statement

or more graphic:

if x == 1: return 1
if x == 2: return 2

with ast.unparse() making it

if x == 1: pass
if x == 2: pass
return 1
return 2

Workaround - put the return statement on a seperate line in the input python sources.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions