Skip to content

Regression: Unstable formatting on long strings #1042

@JelleZijlstra

Description

@JelleZijlstra

I tested Black master on our codebase in preparation for a release, but found that Black failed to format 17 files (the previous release didn't crash on any of our files). It's not clear that all of these have the same root cause, but here's one I minimized somewhat:

$ black infra-common/qroxy/qroxy.py 
error: cannot format infra-common/qroxy/qroxy.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: /tmp/blk_i040l_hj.log
Oh no! 💥 💔 💥
1 file failed to reformat.
$ cat /tmp/blk_i040l_hj.log 
--- source
+++ first pass
@@ -1,10 +1,10 @@
 async def show_status():
     while True:
         try:
             if report_host:
                 data = (
-                    f"{boxname},{alive_server_connections},{server_queue.size()},{requester_queue.size()}"
-                ).encode()
+                    f"{boxname},{alive_server_connections},{server_queue.size()},{requester_queue.size()}".encode()
+                )
         except Exception as e:
             log.error(f"show_status thread encounters exception: {e}")
 
--- first pass
+++ second pass
@@ -1,10 +1,8 @@
 async def show_status():
     while True:
         try:
             if report_host:
-                data = (
-                    f"{boxname},{alive_server_connections},{server_queue.size()},{requester_queue.size()}".encode()
-                )
+                data = f"{boxname},{alive_server_connections},{server_queue.size()},{requester_queue.size()}".encode()
         except Exception as e:
             log.error(f"show_status thread encounters exception: {e}")
 
$ cat infra-common/qroxy/qroxy.py 
async def show_status():
    while True:
        try:
            if report_host:
                data = (
                    f"{boxname},{alive_server_connections},{server_queue.size()},{requester_queue.size()}"
                ).encode()
        except Exception as e:
            log.error(f"show_status thread encounters exception: {e}")

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions