Skip to content
This repository was archived by the owner on Apr 15, 2026. It is now read-only.
This repository was archived by the owner on Apr 15, 2026. It is now read-only.

Python language parser does not properly indent else clause in for and while loops #1363

Closed

Description

@sergeichestakov

Describe the issue

It seems the Python parser does not correctly handle for/else loops and while/else loops, particularly with respect to indentation in nested blocks.

Admittedly, I myself only just found this out but turns out an else clause in a while or for loop is valid Python code (see docs and examples) so I believe the Python parser should handle it appropriately and indent else clauses the same as it does with a matching if statement.

See repro gif below to showcase what I mean:

python-for-while-indentation-bug

Browser and platform

latest MacOS, Firefox (but should repro in all)

Reproduction link

https://replit.com/@SergeiChestakov/cm-py-indentation-bug

Activity

  1. marijnh commented on Mar 28, 2024

    @marijnh
    Member

    Attached patch adds indentation logic that should handle this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

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