Instagram / Instagram/LibCST

Invalid code generated for `Comparison` with missing parens

Open
#911 0 comments 0 reactions 0 assignees View on GitHub
bug parsing
Dominant language
Python
Stars
1.9k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

```python
from libcst import *

node = Comparison(
left=Name("a"),
comparisons=[
ComparisonTarget(
Equal(whitespace_before=ParenthesizedWhitespace(indent=True)),
Name("b"),
),
],
)

code = Module([]).code_for_node(node)
parse_module(code) # error, invalid syntax!
```

Related to #287 and #531; found via https://github.com/Zac-HD/shed/issues/84.

Contributor guide

Open the contributing guide

Research direction

Start by running the provided Python reproduction and trace `Module([]).code_for_node` through `Comparison` serialization. Add a regression test for the missing-parentheses case, with completion defined as generated code that `parse_module` accepts without a syntax error.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
compilers
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.