google / google/yapf

Ternary conditionals within F Strings Raise IndexError

Open
#1,215 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Python
Stars
14k
Forks
904
PR merge metrics
No merged PRs in 30d

Description

**Example:**

yapf_example.py contents:
```python yapf_example.py

print(f"This Fails, but is legal: {"Should be fine" if True else "But it's not"}")
```

**Running Yapf:**
`python -m yapf yapf_example.py`

**Result:**

```
...
return '{}:{}:{}: {}'.format(e.args[1][0], e.args[1][1], e.args[1][2], e.msg)
~~~~~~^^^
IndexError: tuple index out of range
```

**Yapf version**
0.40.2 (Latest at time of writing)

This might be related to [PEP 701](https://github.com/google/yapf/issues/1136), but if memory serves, this has been an issue since before 3.12.

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.