-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Describe the bug
When running black using pre-commit against a generated Django migration file, the following error is observed:
➜ backend git:(main) ✗ pre-commit run black --all-files
black....................................................................Failed
- hook id: black
- exit code: 123
error: cannot format backend/src/black_test.py: maximum recursion depth exceeded while calling a Python object
Oh no! 💥 💔 💥
167 files left unchanged, 1 file failed to reformat.
To Reproduce
Here is a file that can reproduce the above issue: https://gist.github.com/trumpet2012/057e1e6bc381081e06a2eaf9e22db45a
Install pre-commit: https://pre-commit.com/index.html#installation
Our pre-commit config is:
default_language_version:
python: python3
exclude: (^|/)\.idea/
repos:
- repo: https://github.com/psf/black
rev: 22.10.0
hooks:
- id: black
args:
# enable preview mode to get the new string processing
- --previewThen running:
$ pre-commit run black --all-filesResults in the above error.
Expected behavior
Black should be able to correctly reformat the file.
Environment
- Black's version: 22.10.0
- OS and Python version: Mac OS Monterey, Python 3.9.14
- pre-commit version: 2.20.0
Additional context
It works when you run black without the --preview flag.
Interestingly, it also works running black directly (bypassing pre-commit) even with the --preview flag enabled.
Also when I was generating the example file above, I was going through and replacing our internal column names and help text with fake data and when I replaced the help_text= strings with just Lorem ipsum dolores it also worked correctly. Increasing the length of the help text strings then caused the issue to reappear.