Instagram / Instagram/LibCST

StarredDictElement can produce syntactically incorrect output

Open
#519 2 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

eg I expect the following to generate `'{"ham": "spam", **({"x": x} if x else {})}'`

```python
from libcst import (
Dict,
DictElement,
SimpleString,
Name,
LeftParen,
RightParen,
StarredDictElement,
IfExp,
Module,
parse_expression,
)

d = Module(
[
Dict(
elements=[
DictElement(
key=SimpleString(value='"ham"'), value=SimpleString(value='"spam"')
),
StarredDictElement(
value=IfExp(
test=Name(value="x"),
body=Dict(
elements=[
DictElement(
key=SimpleString(value='"x"'), value=Name(value="x")
)
]
),
orelse=Dict(elements=[]),
)
),
]
)
]
)
parse_expression(d.code) # SyntaxError
assert d.code == '{"ham": "spam", **({"x": x} if x else {})}'
```

however I get `'{"ham": "spam", **{"x": x} if x else {}}'`

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.