Skip to content

*...else...else dedentation #56

Description

@kbrose

Minimal code example:

What the code looks like before pressing enter:

if True:
    for i in range(5):
        print(i)
    else:
        print('no break!')
        else:|

What I want the code to look like after pressing enter:

if True:
    for i in range(5):
        print(i)
    else:
        print('no break!')
else:|

What the code actually looks like after pressing enter:

if True:
    for i in range(5):
        print(i)
    else:
        print('no break!')
    else:|

Also, starting from

if True:
    for i in range(5):
        print(i)
    else:
        print('no break!')
    else:|

should end up with the desired behavior shown above too.

Typically, I don't dedent past the point where the else/elif/except/finally keyword could be placed and still be syntactically correct, but in cases like these where we've already "consumed" the for's (or while's or try's) else, we know that the final else must be meant for the if.

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions