Skip to content

maximum recursion depth exceeded while calling a Python object #3340

@trumpet2012

Description

@trumpet2012

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
          - --preview

Then running:

$ pre-commit run black --all-files

Results 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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    C: crashBlack is crashingC: preview styleIssues with the preview and unstable style. Add the name of the responsible feature in the title.F: stringsRelated to our handling of stringsT: bugSomething isn't workinghelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions