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

yapf: enable comments inside expression cause infinite hang #3026

Closed
danthedeckie opened this issue Apr 21, 2022 · 3 comments · Fixed by #3158
Closed

yapf: enable comments inside expression cause infinite hang #3026

danthedeckie opened this issue Apr 21, 2022 · 3 comments · Fixed by #3158
Labels
F: fmtoff fmt: off implementation T: bug Something isn't working

Comments

@danthedeckie
Copy link

Describe the bug

If you have yapf: enable comments inside an expression, you can cause black to hang:

To Reproduce

with file.py as:

def test_func():
    # yapf: disable
    if a:
        return True
    # yapf: enable
    elif b:
        return True

    return False
$ black file.py

It hangs forever.

Expected behavior

It should not hang.

At the very least it should give an error.

Preferably it should ignore those comments and not break anything.

Environment

  • Black's version: black, 22.3.0 (compiled: yes)
  • OS and Python version: Python 3.8 & 3.10, mac OS 12.3

Also happens on the https://black.vercel.app/

@danthedeckie danthedeckie added the T: bug Something isn't working label Apr 21, 2022
@danthedeckie
Copy link
Author

# yapf: disable
if a:
    return True
# yapf: enable
elif b:
    return False

is the smallest I can reduce it to.

It seems that the yapf: disable is needed as well.

@danthedeckie
Copy link
Author

And version hunting, it seems (for me) to crop up between:
black==19.10b0 (good - doesn't hang)
and
black==20.8b0 (bad - does hang)

Hopefully that helps narrow it down.

@danthedeckie
Copy link
Author

danthedeckie commented Apr 21, 2022

And trying to find the problem w/ git bisect narrows it down to: #1325

892eddacd215d685e136686b7f629ade70adca83 is the first bad commit
commit 892eddacd215d685e136686b7f629ade70adca83
Author: otstrel <otstrel@gmail.com>
Date:   Fri May 8 15:37:17 2020 +0300

    Fix for "# fmt: on" with decorators (#1325)

 black.py                | 49 ++++++++++++++++++++++++++++++++++++++++---------
 tests/data/fmtonoff4.py | 31 +++++++++++++++++++++++++++++++
 tests/test_black.py     |  8 ++++++++
 3 files changed, 79 insertions(+), 9 deletions(-)
 create mode 100644 tests/data/fmtonoff4.py

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: fmtoff fmt: off implementation T: bug Something isn't working
Projects
None yet
2 participants