Instagram / Instagram/LibCST

LibCST drops whitespace before `:` in `except` / `except*` handlers without `as`

Open
#1,457 1 comment 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
1.9k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

Version
LibCST 1.8.6 on Python 3.12

Reproducer:
```
import libcst as cst

src = "try: pass\nexcept A :\n pass\n"
out = cst.parse_module(src).code

print(repr(out))
assert out == src
```

Actual Output
`'try: pass\nexcept A:\n pass\n'`

Expected Output
`'try: pass\nexcept A :\n pass\n'`

The issue also reproduces with the following input:

```
try: pass
except* A :
pass
```

But this form appears to preserve correctly:

```
try: pass
except A as e :
pass
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.