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

Black reports code that is not equivalent when formatting a doc-string in a file that contains the exec statement #1771

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

Comments

@deymundson
Copy link

Description
If a file contains a doc-string that requires formatting, and the exec statement, Black will complain that the change to the doc-string is not equivalent.

Note that this only applies to the exec statement. The exec() function works as expected. Therefore this issue only applies if the target Python version is 2.7.

To Reproduce

  1. Using a file with the following contents
def Foo():
    """
    """


exec ""

  1. Run Black on it with these arguments --target-version=py27
  2. See error

Expected behavior
Black would format the file, including the doc-string, without an error stating that the code is not equivalent.

Environment

  • Version: 20.8b1
  • OS and Python version: Windows/Python 3.9

Does this bug also happen on master?
Yes

Additional context
The same issue exists when Black reformats a doc-string with an Exception handler that uses the "comma" syntax to get the instance of the exception. i.e. except Exception, e:
See here for a snippet in the Black playground.

@deymundson deymundson added the T: bug Something isn't working label Oct 20, 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

Closing as a duplicate of #1635 (er actually this is a duplicate of #1663 apparently)..

(black) ichard26@acer-ubuntu:~/programming/oss/black$ python --version ; git log -n 1 --oneline
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 Foo():
    """
    """


exec ""
(black) ichard26@acer-ubuntu:~/programming/oss/black$ black temp.py -t py27 --fast --diff --color
--- temp.py	2020-10-26 22:16:15.861441 +0000
+++ temp.py	2020-10-26 22:16:42.500120 +0000
@@ -1,6 +1,5 @@
 def Foo():
-    """
-    """
+    """"""
 
 
 exec ""
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