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

Unstable formatting in long assignment expression with square brackets and parentheses #2093

Closed
jtv8 opened this issue Apr 8, 2021 · 1 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

Comments

@jtv8
Copy link

jtv8 commented Apr 8, 2021

Describe the bug It is possible to produce unstable formatting when Black tries to break down a long assignment expression by expanding both square brackets and parentheses to span multiple lines.

To Reproduce Steps to reproduce the behavior:

  1. Take this file:
if True:
    if True:
        if True:
            if True:
                if True:
                    twelve_chars.loc[
                        twelve_chars.Attrib == 'ABCD',
                        ninechars + 'SevenCHR' + four + '_X'
                    ] = (some_numerator / denominator)
  1. Run Black on it with these arguments: default arguments
  2. See error
error: cannot format <REDACTED>.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: <REDACTED>\blk_dr8xohwx.log
Oh no! \U0001f4a5 \U0001f494 \U0001f4a5
1 file failed to reformat.

Log output:

Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -2,8 +2,8 @@
     if True:
         if True:
             if True:
                 if True:
                     twelve_chars.loc[
-                        twelve_chars.Attrib == 'ABCD',
-                        ninechars + 'SevenCHR' + four + '_X'
+                        twelve_chars.Attrib == "ABCD",
+                        ninechars + "SevenCHR" + four + "_X",
                     ] = (some_numerator / denominator)
--- first pass
+++ second pass
@@ -4,6 +4,8 @@
             if True:
                 if True:
                     twelve_chars.loc[
                         twelve_chars.Attrib == "ABCD",
                         ninechars + "SevenCHR" + four + "_X",
-                    ] = (some_numerator / denominator)
+                    ] = (
+                        some_numerator / denominator
+                    )

Expected behavior

Either of the following outputs would be acceptable::

if True:
    if True:
         if True:
            if True:
                 if True:
                     twelve_chars.loc[
                         twelve_chars.Attrib == "ABCD",
                         ninechars + "SevenCHR" + four + "_X",
                     ] = (some_numerator / denominator)

or

if True:
    if True:
         if True:
            if True:
                 if True:
                     twelve_chars.loc[
                         twelve_chars.Attrib == "ABCD",
                         ninechars + "SevenCHR" + four + "_X",
                     ] = (
                         some_numerator / denominator
                     )

Environment (please complete the following information):

  • Version: 20.8b1
  • OS and Python version: Windows/Python 3.9.2

Does this bug also happen on master? Yes

Additional context None

@jtv8 jtv8 added the T: bug Something isn't working label Apr 8, 2021
@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Apr 10, 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!

@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Apr 25, 2021
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

2 participants