Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

maximum recursion depth exceeded while calling a Python object #3340

Closed
trumpet2012 opened this issue Oct 17, 2022 · 2 comments · Fixed by #3467
Closed

maximum recursion depth exceeded while calling a Python object #3340

trumpet2012 opened this issue Oct 17, 2022 · 2 comments · Fixed by #3467
Labels
C: crash Black is crashing C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. F: strings Related to our handling of strings help wanted Extra attention is needed T: bug Something isn't working

Comments

@trumpet2012
Copy link

trumpet2012 commented Oct 17, 2022

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.

@trumpet2012 trumpet2012 added the T: bug Something isn't working label Oct 17, 2022
@ichard26 ichard26 added help wanted Extra attention is needed C: crash Black is crashing labels Oct 18, 2022
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 30, 2022

Thanks for the report!

I believe pre-commit doesn't use wheels, which might explain some of your reproducibility issues (e.g. maybe there's some interaction with mypyc). I can reproduce on main with my editably installed checkout with --preview. Doesn't look like a recent regression either.

The stacktrace (visible by using -v) is just a bunch of:

  File "/Users/shantanu/dev/black/src/black/linegen.py", line 504, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
  File "/Users/shantanu/dev/black/src/black/linegen.py", line 1217, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/shantanu/dev/black/src/black/linegen.py", line 504, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
  File "/Users/shantanu/dev/black/src/black/linegen.py", line 1217, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))

Edit: earlier version of this comment claimed it reproduced without --preview. It does need --preview, I just put the file inside black's dir, so we used --preview automatically.

@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Oct 30, 2022

Goes back at least all the way to ESP being added to preview (this issue should probably get an ESP label)

@ichard26 ichard26 added the F: strings Related to our handling of strings label Oct 30, 2022
@JelleZijlstra JelleZijlstra added the C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: crash Black is crashing C: preview style Issues with the preview and unstable style. Add the name of the responsible feature in the title. F: strings Related to our handling of strings help wanted Extra attention is needed T: bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants