-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Description
Describe the bug
pre-commit hook fails to format code with the Structural Pattern Matching PEP 0622.
To Reproduce
Files
.pre-commit-config.yaml
:
repos:
- repo: https://github.com/psf/black
rev: 21.12b0
hooks:
- id: black
pyproject.toml
:
[tool.black]
target-version = ["py310"]
file_with_310_features.py
match "this":
case "that":
print(1 + 2)
file_without_310_features.py
print(1 + 2)
Setup
pip install black==21.12b0 pre-commit
git init
git add .
pre-commit install
And run it with these arguments:
pre-commit run black --all-files
The resulting error is:
black....................................................................Failed
- hook id: black
- exit code: 123
- files were modified by this hook
reformatted file_without_310_features.py
error: cannot format file_with_310_features.py: cannot use --safe with this file; failed to parse source file.
Oh no! \U0001f4a5 \U0001f494 \U0001f4a5
1 file reformatted, 1 file failed to reformat.
Expected behavior
Pre-commit hooks should format both file_with_310_features.py
and file_without_310_features.py
; they are valid python 3.10.
Environment
- Black's version: 21.12b0
- OS and Python version: Windows 10, Python 3.10.0
FYI
I can format the file with Python 3.10 features just fine:
black file_with_310_features.py
reformatted file_with_310_features.py
All done! ✨ 🍰 ✨
1 file reformatted,