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

Fix an infinite recursion error. #3444

Merged
merged 2 commits into from Dec 16, 2022
Merged

Fix an infinite recursion error. #3444

merged 2 commits into from Dec 16, 2022

Conversation

yilei
Copy link
Contributor

@yilei yilei commented Dec 16, 2022

Description

This bug appears to have existed earlier. But it's now triggered on the added test after #3440 on the complex dict value.

The infinite recursion happens when getting the second_opinion. Example traceback:

Traceback (most recent call last):
  File "/Users/yileiyang/github.com/yilei/black/src/black/__init__.py", line 1077, in format_str
    dst_contents = _format_str_once(src_contents, mode=mode)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/__init__.py", line 1109, in _format_str_once
    for line in transform_line(
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1442, in run_transformer
    second_opinion = run_transformer(
                     ^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1442, in run_transformer
    second_opinion = run_transformer(
                     ^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1442, in run_transformer
    second_opinion = run_transformer(
                     ^^^^^^^^^^^^^^^^
  [Previous line repeated 950 more times]
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1418, in run_transformer
    result.extend(transform_line(transformed_line, mode=mode, features=features))
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 577, in transform_line
    result = run_transformer(line, transform, mode, features, line_str=line_str)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/linegen.py", line 1414, in run_transformer
    for transformed_line in transform(line, features):
  File "/Users/yileiyang/github.com/yilei/black/src/black/trans.py", line 240, in __call__
    match_result = self.do_match(line)
                   ^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/trans.py", line 883, in do_match
    match_result = self.do_splitter_match(line)
                   ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/trans.py", line 1207, in do_splitter_match
    idx = string_parser.parse(LL, string_idx)
          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/trans.py", line 2088, in parse
    while idx < len(leaves) and self._next_state(leaves[idx]):
                                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/trans.py", line 2106, in _next_state
    if is_empty_par(leaf):
       ^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/nodes.py", line 756, in is_empty_par
    return is_empty_lpar(leaf) or is_empty_rpar(leaf)
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/yileiyang/github.com/yilei/black/src/black/nodes.py", line 760, in is_empty_lpar
    return leaf.type == token.LPAR and leaf.value == ""
           ^^^^^^^^^^^^^^^^^^^^^^^
RecursionError: maximum recursion depth exceeded in comparison

Checklist - did you ...

  • Add an entry in CHANGES.md if necessary?
  • Add / update tests if necessary?
  • Add new / update outdated documentation?

@github-actions
Copy link

diff-shades reports zero changes comparing this PR (6627322) to main (aafc21a).


What is this? | Workflow run | diff-shades documentation

Copy link
Collaborator

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for noticing and fixing!

@JelleZijlstra JelleZijlstra added the skip news Pull requests that don't need a changelog entry. label Dec 16, 2022
@JelleZijlstra JelleZijlstra merged commit 7816393 into psf:main Dec 16, 2022
@yilei yilei deleted the recursion branch December 16, 2022 18:45
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news Pull requests that don't need a changelog entry.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants