LibCST icon indicating copy to clipboard operation
LibCST copied to clipboard

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

Open fraglantia opened this issue 5 months ago • 1 comments

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

fraglantia avatar Jun 09 '26 04:06 fraglantia

@fraglantia , is this issue still on or solved internally?

RjyavardhanSingh avatar Sep 02 '26 19:09 RjyavardhanSingh