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

Hang when parsing # fmt: on in the middle of an expression #2015

Closed
remyjette opened this issue Mar 1, 2021 · 1 comment · Fixed by #3158
Closed

Hang when parsing # fmt: on in the middle of an expression #2015

remyjette opened this issue Mar 1, 2021 · 1 comment · Fixed by #3158
Labels
C: performance Black is too slow. Or too fast. F: fmtoff fmt: off implementation T: bug Something isn't working

Comments

@remyjette
Copy link

Describe the bug
black hangs when parsing # fmt: on in the middle of an expression

To Reproduce

  1. Take this file
from subprocess import run

path = ["."]
run(
    # fmt: off
    [
        "ls",
        "-la",
    ]
    # fmt: on
    + path,
    check=True,
)
  1. Run Black on it with these arguments --target-version py38
  2. Observe that black never exits.

Expected behavior
Either black should format the file fine (19.10b0 does not have trouble here) or it should error out and tell me it failed to format.

Environment (please complete the following information):

  • Version: [e.g. master] 20.8b1
  • OS and Python version: [e.g. Linux/Python 3.7.4rc1] Linux/Python 3.8.5

Does this bug also happen on master? To answer this, you have two options:

  1. Use the online formatter at https://black.now.sh/?version=master, which will use the
    latest master branch.
  2. Or run Black on your machine:
    • create a new virtualenv (make sure it's the same Python version);
    • clone this repository;
    • run pip install -e .;
    • make sure it's sane by running python -m unittest; and
    • run black like you did last time.

Yes, it is happening on the online formatter as well.

Additional context
If I remove check=True, from my example, it works fine. If I move # fmt: on after + path, it works fine.

We've modified our code to put # fmt: on in a more reasonable location, but still wanted to report it as I wouldn't expect a hang.

@remyjette remyjette added the T: bug Something isn't working label Mar 1, 2021
@ichard26
Copy link
Collaborator

ichard26 commented Mar 3, 2021

Yeah, this is definitely hanging and wow does this (partial) call graph look wrong. Created using 858225d and the code in the bug report.
Screenshot from 2021-03-02 20-22-21

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: performance Black is too slow. Or too fast. F: fmtoff fmt: off implementation T: bug Something isn't working
Projects
None yet
3 participants