Black: Code not equivalent to source: typeshed/stdlib/3/configparser.pyi

Created on 20 Jan 2020  ·  2Comments  ·  Source: psf/black

Hi! I accidentally ran black on my entire venv in a project, and one of the files it spat out "INTERNAL ERROR: Black produced code that is not equivalent to the source." on was typeshed/stdlib/3/configparser.pyi. I'm not sure what version of typeshed that is, but the issue doesn't repro with the current version on GitHub.

Regardless, here's the diff:

--- src
+++ dst
@@ -5135,8 +5135,6 @@
   type_ignores=
     TypeIgnore(
     )  # /TypeIgnore
     TypeIgnore(
     )  # /TypeIgnore
-    TypeIgnore(
-    )  # /TypeIgnore
 )  # /Module

Most helpful comment

Okay, I seem to have an absurdly tiny repro case:

(venv) julia@causeway:/tmp$ cat bad.pyi 
def f():  # type: ignore
    ...
(venv) julia@causeway:/tmp$ black bad.pyi 
error: cannot format bad.pyi: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk_gl3r8wl1.log
Oh no! 💥 💔 💥
1 file failed to reformat.
(venv) julia@causeway:/tmp$ cat /tmp/blk_gl3r8wl1.log
--- src
+++ dst
@@ -25,8 +25,6 @@
         None,  # NoneType
       type_comment=
         None,  # NoneType
     )  # /FunctionDef
   type_ignores=
-    TypeIgnore(
-    )  # /TypeIgnore
 )  # /Module
(venv) julia@causeway:/tmp$ cat good.pyi 
def f():
    ...
(venv) julia@causeway:/tmp$ black good.pyi 
reformatted good.pyi
All done! ✨ 🍰 ✨
1 file reformatted.

All 2 comments

Would you mind sending the version of the file that you were running Black on? Even better would be if you could minimize it to just the part of the file that the bug is triggered on :)

Okay, I seem to have an absurdly tiny repro case:

(venv) julia@causeway:/tmp$ cat bad.pyi 
def f():  # type: ignore
    ...
(venv) julia@causeway:/tmp$ black bad.pyi 
error: cannot format bad.pyi: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk_gl3r8wl1.log
Oh no! 💥 💔 💥
1 file failed to reformat.
(venv) julia@causeway:/tmp$ cat /tmp/blk_gl3r8wl1.log
--- src
+++ dst
@@ -25,8 +25,6 @@
         None,  # NoneType
       type_comment=
         None,  # NoneType
     )  # /FunctionDef
   type_ignores=
-    TypeIgnore(
-    )  # /TypeIgnore
 )  # /Module
(venv) julia@causeway:/tmp$ cat good.pyi 
def f():
    ...
(venv) julia@causeway:/tmp$ black good.pyi 
reformatted good.pyi
All done! ✨ 🍰 ✨
1 file reformatted.
Was this page helpful?
0 / 5 - 0 ratings