google / google/yapf

Support 3.12 feature: PEP 695 Type Parameter Syntax

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

Description

### Issue
In [PEP-695](https://docs.python.org/3/whatsnew/3.12.html#whatsnew312-pep695), running under 3.12 will cause exceptions in YAPF. For example the following two lines of code for testing:

```
type Testing = dict[int | str]
type Testing2 = dict[str: int]
```

The following error message happens:

```
During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "", line 198, in _run_module_as_main
File "", line 88, in _run_code
File "/home/josh.lam/.local/yapf/yapf/__main__.py", line 18, in
yapf.run_main()
File "/home/josh.lam/local/.pyenv/versions/3.12.0/lib/python3.12/site-packages/yapf/__init__.py", line 377, in run_main
sys.exit(main(sys.argv))
^^^^^^^^^^^^^^
File "/home/josh.lam/.local/.pyenv/versions/3.12.0/lib/python3.12/site-packages/yapf/__init__.py", line 136, in main
changed = FormatFiles(
^^^^^^^^^^^^
File "/home/josh.lam/.local/.pyenv/versions/3.12.0/lib/python3.12/site-packages/yapf/__init__.py", line 214, in FormatFiles
changed |= _FormatFile(filename, lines, style_config, no_local_style,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/josh.lam/local/.pyenv/versions/3.12.0/lib/python3.12/site-packages/yapf/__init__.py", line 248, in _FormatFile
raise errors.YapfError(errors.FormatErrorMsg(e))
^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/josh.lam/.local/.pyenv/versions/3.12.0/lib/python3.12/site-packages/yapf/yapflib/errors.py", line 37, in FormatErrorMsg
return '{}:{}:{}: {}'.format(e.args[1][0], e.args[1][1], e.args[1][2], e.msg)
~~~~~~^^^
IndexError: tuple index out of range
>>>>> In file /home/josh.lam/testing.py <<<<<
1,2d0
< type Testing = dict[int | str]
< type Testing2 = dict[str: int]
```

### Other Info
#### Yapf Configuration file:
```
[style]
based_on_style = google

column_limit = 120
split_before_arithmetic_operator = true
```

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.