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

Docstring and raising exception in py2 style generates INTERNAL ERROR #1722

Closed
lodagro opened this issue Sep 23, 2020 · 1 comment
Closed
Labels
R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@lodagro
Copy link

lodagro commented Sep 23, 2020

When running black on the following file an INTERNAL ERROR is raised.

 def bar():
     """some docstring
     """
     try:
         print('do some stuff')
     except Exception, e: 
         pass

This is the generated diff.

--- src
+++ dst
@@ -14,11 +14,11 @@
       body=
         Expr(
           value=
             Constant(
               value=
-                b'some docstring\n    ',  # bytes
+                b'some docstring',  # bytes
             )  # /Constant
         )  # /Expr
         TryExcept(
           body=
             Print(

This the full error:

INTERNAL ERROR: Black produced code that is not equivalent to the source.
  • Version:
    • 20.8b1
    • master 20.8b2.dev24+g6dddbd7
  • OS and Python version: Linux / Python 3.8
@lodagro lodagro added the T: bug Something isn't working label Sep 23, 2020
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Oct 26, 2020
@ichard26
Copy link
Collaborator

ichard26 commented Oct 26, 2020

Hi, I'm closing this as it's a duplicate of #1635 (er actually this is a duplicate of #1663 apparently).

(black) ichard26@acer-ubuntu:~/programming/oss/black$ python --version ; git log --oneline -n 1
Python 3.8.5
4070527 (HEAD -> main, upstream/master, caching) Switch to pytest and tox (#1763)
(black) ichard26@acer-ubuntu:~/programming/oss/black$ cat temp.py
def bar():
    """some docstring
    """
    try:
        print("do some stuff")
    except Exception, e:
        pass
(black) ichard26@acer-ubuntu:~/programming/oss/black$ black temp.py --diff --color
error: cannot format temp.py: 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_9_gz0d1n.log
Oh no! 💥 💔 💥
1 file would fail to reformat.
(black) ichard26@acer-ubuntu:~/programming/oss/black$ black temp.py --diff --color --fast
--- temp.py	2020-10-26 22:51:32.886060 +0000
+++ temp.py	2020-10-26 22:52:06.607420 +0000
@@ -1,7 +1,6 @@
 def bar():
-    """some docstring
-    """
+    """some docstring"""
     try:
         print("do some stuff")
     except Exception, e:
         pass
would reformat temp.py
All done! ✨ 🍰 ✨
1 file would be reformatted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
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