Skip to content

Auto-indent for Python spotty #11909

@cajuntechie

Description

@cajuntechie
  • VSCode Version: 1.5.2
  • OS Version: Windows 8.1 and Ubuntu Linux 16.04

When writing certain Python code, auto-indent/de-indent fails to properly indent/de-indent lines as expected. For example, if I write:

if myVar == 1:
    print("This is equal to 1")
else:
    print ("This is not equal to 1")

The editor fails to automatically indent the "else" statement. it should be able to detect that I am entering an "else" statement and properly handle indentation and de-indentation. The same issue occurs on try/except blocks.

try:
    subprocess.check_output("someprogram.exe")
except CalledProcessException:
    print("The process failed.")

The editor should be able to detect when it sees the except block starter and properly de--indent the code as expected. As it stands, both the if/else and try/except blocks look like this when entered into the editor:

if myvar == 1:
    print("This is equal to 1")
    else:
        print("This is not equal to 1")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions