google / google/yapf

Formatted string literals

Open
#619 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

Apparently YAPF is not able to properly parse [formatted string literals](https://docs.python.org/3/whatsnew/3.6.html#whatsnew36-pep498) (introduced in Python 3.6).

Here's a minimal example (`deleteme.py`):

```
width = 21
x = 10
label = f"|{x:^{width}}|"
print(label)
```

The above code---which is valid python and, as expected, prints `| 10 |`(Github's markdown processor has removed some spaces, but I see what I expect on my screen)---fails to be parsed by yapf (version 0.24.0), giving the following traceback:

```
Traceback (most recent call last):
File "/usr/local/bin/yapf", line 11, in
sys.exit(run_main())
File "/usr/local/lib/python2.7/site-packages/yapf/__init__.py", line 317, in run_main
sys.exit(main(sys.argv))
File "/usr/local/lib/python2.7/site-packages/yapf/__init__.py", line 205, in main
verbose=args.verbose)
File "/usr/local/lib/python2.7/site-packages/yapf/__init__.py", line 255, in FormatFiles
in_place, print_diff, verify, verbose)
File "/usr/local/lib/python2.7/site-packages/yapf/__init__.py", line 280, in _FormatFile
logger=logging.warning)
File "/usr/local/lib/python2.7/site-packages/yapf/yapflib/yapf_api.py", line 91, in FormatFile
verify=verify)
File "/usr/local/lib/python2.7/site-packages/yapf/yapflib/yapf_api.py", line 129, in FormatCode
tree = pytree_utils.ParseCodeToTree(unformatted_source)
File "/usr/local/lib/python2.7/site-packages/yapf/yapflib/pytree_utils.py", line 127, in ParseCodeToTree
raise e
File "deleteme.py", line 3
label = f"{x:^{width}}"
^
SyntaxError: invalid syntax
```

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.