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: Black produced different code on the second pass of the formatter #1853

Closed
semajson opened this issue Dec 1, 2020 · 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

@semajson
Copy link

semajson commented Dec 1, 2020

Describe the bug When running black over the following code:

def verify_data(number_of_messages, pdu_payload, binascii):
    udh_prefix = "test"

    # Verify the UDH header and the data_coding.
    assert pdu_payload.startswith(udh_prefix + chr(number_of_messages)), (
        "Expected PDU payload to begin with (as hex) "
        "{udh_prefix}{number_of_messages}, but was {actual}".format(
            udh_prefix=binascii.b2a_hex(udh_prefix),
            number_of_messages=binascii.b2a_hex(chr(number_of_messages)),
            actual=binascii.b2a_hex(pdu_payload)))

The error INTERNAL ERROR: Black produced different code on the second pass of the formatter is reported

To Reproduce Run black over code snippet posted above

Expected behavior Black formats the file without error

Environment :

  • Version: 20.8b1
  • OS and Python version: Centos 7 / Python 2.7.5 (although code was from a python 2 script, I don't think it's a python 2 specific issue)

Does this bug also happen on master? Yes, it repos on https://black.now.sh/?version=master

Additional context Output of the of the diff file:

Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,11 +1,12 @@
-
 def verify_data(number_of_messages, pdu_payload, binascii):
     udh_prefix = "test"
 
     # Verify the UDH header and the data_coding.
     assert pdu_payload.startswith(udh_prefix + chr(number_of_messages)), (
         "Expected PDU payload to begin with (as hex) "
         "{udh_prefix}{number_of_messages}, but was {actual}".format(
             udh_prefix=binascii.b2a_hex(udh_prefix),
             number_of_messages=binascii.b2a_hex(chr(number_of_messages)),
-            actual=binascii.b2a_hex(pdu_payload)))
+            actual=binascii.b2a_hex(pdu_payload),
+        )
+    )
--- first pass
+++ second pass
@@ -1,12 +1,11 @@
 def verify_data(number_of_messages, pdu_payload, binascii):
     udh_prefix = "test"
 
     # Verify the UDH header and the data_coding.
-    assert pdu_payload.startswith(udh_prefix + chr(number_of_messages)), (
-        "Expected PDU payload to begin with (as hex) "
-        "{udh_prefix}{number_of_messages}, but was {actual}".format(
-            udh_prefix=binascii.b2a_hex(udh_prefix),
-            number_of_messages=binascii.b2a_hex(chr(number_of_messages)),
-            actual=binascii.b2a_hex(pdu_payload),
-        )
+    assert pdu_payload.startswith(
+        udh_prefix + chr(number_of_messages)
+    ), "Expected PDU payload to begin with (as hex) " "{udh_prefix}{number_of_messages}, but was {actual}".format(
+        udh_prefix=binascii.b2a_hex(udh_prefix),
+        number_of_messages=binascii.b2a_hex(chr(number_of_messages)),
+        actual=binascii.b2a_hex(pdu_payload),
     )
@semajson semajson added the T: bug Something isn't working label Dec 1, 2020
@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Dec 1, 2020
@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

2 participants