vsc-python-indent icon indicating copy to clipboard operation
vsc-python-indent copied to clipboard

*...else...else dedentation

Open kbrose opened this issue 5 years ago • 0 comments

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.

kbrose avatar Nov 19 '19 14:11 kbrose