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

INTERNAL ERROR: unstable assert formatting for certain length strings #1618

Closed
jonppe opened this issue Aug 22, 2020 · 1 comment
Closed
Labels
C: unstable formatting Formatting changed on the second pass T: bug Something isn't working

Comments

@jonppe
Copy link

jonppe commented Aug 22, 2020

Black is not able to reliably format code with assert and certain length string with formatting.
This happens with both 19.10b0 and the current master 19.10b1.dev154+gcd3a93a.d20200822.
19.3b0 does not have the issue.

--- source
+++ first pass
@@ -1,4 +1,6 @@
-assert some_type_of_boolean_expression, (
-    "format-string-and-arguments with certain total length %s %s xxxxx"
-    % (xxxxxxxxx, xxx)
+assert (
+    some_type_of_boolean_expression
+), "format-string-and-arguments with certain total length %s %s xxxxx" % (
+    xxxxxxxxx,
+    xxx,
 )
--- first pass
+++ second pass
@@ -1,6 +1,4 @@
-assert (
-    some_type_of_boolean_expression
-), "format-string-and-arguments with certain total length %s %s xxxxx" % (
-    xxxxxxxxx,
-    xxx,
+assert some_type_of_boolean_expression, (
+    "format-string-and-arguments with certain total length %s %s xxxxx"
+    % (xxxxxxxxx, xxx,)
 )

Some additional notes:

If I remove one x, black reliably gives me output:

assert (
    some_type_of_boolean_expression
), "format-string-and-arguments with certain total length %s %s xxxx" % (xxxxxxxxx, xxx)

Anyway, here the longest line is 88 chars so this format can not be used with the original code.

On the other hand, if I add one X to the original code, black again works and gives me format:

assert some_type_of_boolean_expression, (
    "format-string-and-arguments with certain total length %s %s xxxxxX"
    % (xxxxxxxxx, xxx)

This is a format that could be used with the original code.
And this seems to be same format than output of the first pass.
Finally, black uses this same format if I add a trailing comma to the string format arguments:

assert some_type_of_boolean_expression, (
    "format-string-and-arguments with certain total length %s %s xxxxx"
    % (xxxxxxxxx, xxx,)
)

But I wonder is this against the "magical trailing comma" rule?

@jonppe jonppe added the T: bug Something isn't working label Aug 22, 2020
@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Aug 22, 2020
@ichard26
Copy link
Collaborator

Fixed by #1621.

(black-rHKUX7ap) R:\Programming\black>type temp.py
assert some_type_of_boolean_expression, (
    "format-string-and-arguments with certain total length %s %s xxxxx"
    % (xxxxxxxxx, xxx)
)
(black-rHKUX7ap) R:\Programming\black>git checkout cd3a93a
HEAD is now at cd3a93a Property-based fuzz test

(black-rHKUX7ap) R:\Programming\black>black temp.py --check
error: cannot format temp.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: C:\Users\User\AppData\Local\Temp\blk_7487p0vh.log
Oh no! 💥 💔 💥
1 file would fail to reformat.

(black-rHKUX7ap) R:\Programming\black>git checkout 586d24236e6b57bc3b5da85fdbe2563835021076
Previous HEAD position was cd3a93a Property-based fuzz test
HEAD is now at 586d242 Address pre-existing trailing commas when not in the rightmost bracket pair

(black-rHKUX7ap) R:\Programming\black>black temp.py --check
would reformat temp.py
Oh no! 💥 💔 💥
1 file would be reformatted.

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 T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants