Skip to content

Unstable formatting with "# type: ignore" comment #1061

@The-Compiler

Description

@The-Compiler

Operating system: Arch Linux
Python version: 3.7
Black version: 19.3b0, 19.3b1.dev96+g57ab909
Does also happen on master: yes

I think I'm seeing a "INTERNAL ERROR: Black produced different code on the second pass of the formatter." which is different from others I find here (#954, #1042, #1044).

With this code:

class Test:
    def _init_host(self, parsed) -> None:
        if (parsed.hostname is None or  # type: ignore
                not parsed.hostname.strip()):
            pass

I get this diff:

--- source
+++ first pass
@@ -1,6 +1,8 @@
 class Test:
     def _init_host(self, parsed) -> None:
-        if (parsed.hostname is None or  # type: ignore
-                not parsed.hostname.strip()):
+        if (
+            parsed.hostname is None
+            or not parsed.hostname.strip()  # type: ignore
+        ):
             pass
 
--- first pass
+++ second pass
@@ -1,8 +1,7 @@
 class Test:
     def _init_host(self, parsed) -> None:
         if (
-            parsed.hostname is None
-            or not parsed.hostname.strip()  # type: ignore
+            parsed.hostname is None or not parsed.hostname.strip()  # type: ignore
         ):
             pass
 

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