# python: Fix incorrect indenting of \`except\`, \`finally\`, \`else\`, and \`elif\` control flow \(\#27428\) · gitcafe/zed

[View on GitCafe](https://git.cafe/gitcafe/zed/commit/e273de5490c6a8fbce053ab2a53d6cbf7faf6a17)

Repository: [gitcafe/zed](https://git.cafe/gitcafe/zed)

Visibility: public

Requested revision: e273de5490c6a8fbce053ab2a53d6cbf7faf6a17

Requested commit: e273de5490c6a8fbce053ab2a53d6cbf7faf6a17

Commit: e273de5490c6a8fbce053ab2a53d6cbf7faf6a17

Tree: ad5cde0f8cfbe465b69f2528b7dfb7ea819ce746

Author: Ben Kunkle

Committer: GitHub

## Message

````
python: Fix incorrect indenting of `except`, `finally`, `else`, and `elif` control flow (#27428)

Closes #10832

Note: This PR only fixes the issue where when entering one of `except`,
`finally`, `else`, and `elif` after another block like so:

```python
try:
    for i in range(n):
        pass
except:|
```

The `except` would be indented resulting in the following:

```python
try:
    for i in range(n):
        pass
    except:|
```

This PR does not fix a separate issue in which the indentation is not
corrected from the second example to the first, i.e. if example 2 is
typed verbatim in Zed it will not auto-indent to look like example 1.
Handling of this case would likely require specific logic to handle, or
changes to the tree-sitter grammar for Python, as the current grammar
results in ERROR nodes that obscure the natural structure (cannot tie
the `except` to the `try`)

Release Notes:

- Fixed an issue where `except`, `finally`, `else`, and `elif` control
flow keywords in Python would be incorrectly indented when entered at
the correct level of indentation.
````

## Parents

- [7046b9641d9e1a3a137b1a188f726c224f125a4b](https://git.cafe/gitcafe/zed/commit/7046b9641d9e1a3a137b1a188f726c224f125a4b?format=markdown)

[Source at this commit](https://git.cafe/gitcafe/zed/tree/e273de5490c6a8fbce053ab2a53d6cbf7faf6a17?format=markdown)
