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

Black produced different code on the second pass of the formatter #1995

Closed
tcbegley opened this issue Feb 21, 2021 · 2 comments
Closed

Black produced different code on the second pass of the formatter #1995

tcbegley opened this issue Feb 21, 2021 · 2 comments
Labels
C: unstable formatting Formatting changed on the second pass R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@tcbegley
Copy link

Describe the bug

Ran black on some unit tests and got the error

 INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.

I've included a minimal reproduction of the failing code below.

To Reproduce

  1. Take this file

    def test_shape():
        assert some_function(
            data,
            more_data,
            kwarg1=kwarg1_longish_name,
            kwarg2=kwarg2_longish_name,
            kwarg3=kwarg3,
            kwarg4=kwarg4
        ).shape == (dim1_shape,)
  2. Run Black on it with no arguments: black .

  3. See error:

    error: cannot format test_shape.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.
    

Environment (please complete the following information):

  • Version: master & 20.8b1
  • OS and Python version: macOS + Python 3.8.6

Does this bug also happen on master?
Yes

Additional context

The first pass adds a trailing comma to kwarg4. The second pass wraps the expression in the assert statement in parentheses and expands onto multiple lines. Manually adding the trailing comma before running Black resolves the issue.

@tcbegley tcbegley added the T: bug Something isn't working label Feb 21, 2021
@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Feb 21, 2021
@mvolfik
Copy link

mvolfik commented Feb 22, 2021

Probably the same issue as in #1629 , as black processes this file without issue with #1958 checked out

@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Apr 25, 2021
@ichard26
Copy link
Collaborator

Hello!

All reproduction cases in this issue format without error on master. The fixing commit was 8672af3 from PR GH-2126. I'll be marking this issue as a duplicate of GH-1629 since that's what GH-2126 aimed to fix and it's highly likely this issue falls under GH-1629.

Since we use the issue tracker as a reflection of what's on master, I'll be closing this issue. If you have any issues, especially with the new (but stable) output, please open a new issue. Oh and the fix should be available in a published release soon, see GH-2125 for more info.

Thank you for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: unstable formatting Formatting changed on the second pass R: duplicate This issue or pull request already exists T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants