Instagram / Instagram/LibCST

cst.IfExp test/body print order differs from lexical order in code

Open
#875 1 comment 0 reactions 0 assignees View on GitHub
enhancement good first issue parsing
Dominant language
Python
Stars
1.9k
Forks
229
PR merge metrics
No merged PRs in 30d

Description

`leave_IfExp_body` is executed before `leave_IfExp_test`, which I think is by design since the body appears before the test in code (although impractical in my case since it can otherwise be treated just like an `If`), but when printing an `IfExp` it prints the `test` before `body` - which made it quite confusing to figure out what was going on.

The `__init__` also has it's `test` argument before `body`.

```python
cst.parse_expression('True if False else None')
Out[19]:
IfExp(
test=Name(
value='False',
lpar=[],
rpar=[],
),
body=Name(
value='True',
lpar=[],
rpar=[],
),
orelse=Name(
value='None',
lpar=[],
rpar=[],
),
lpar=[],
rpar=[],
whitespace_before_if=SimpleWhitespace(
value=' ',
),
whitespace_after_if=SimpleWhitespace(
value=' ',
),
whitespace_before_else=SimpleWhitespace(
value=' ',
),
whitespace_after_else=SimpleWhitespace(
value=' ',
),
)
```

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.