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

Docstrings not part of a function are incorrectly labeled as non-equivalent code #4306

Closed
Anonymous941 opened this issue Apr 12, 2024 · 1 comment
Labels
T: bug Something isn't working

Comments

@Anonymous941
Copy link

Anonymous941 commented Apr 12, 2024

Describe the bug

When docstrings that are ignored by the Python interpreter (e.g. in if statements) are reformatted, it causes the

To Reproduce

This very simple program can reproduce the error:

if True:
    """
test
    """

The resulting error is:

error: cannot format file.py: INTERNAL ERROR: Black produced code that is not equivalent to the source.  Please report a bug on https://github.com/psf/black/issues.

Log file:

--- src
+++ dst
@@ -6,11 +6,11 @@
             value=
             Constant(
                 kind=
                 None,  # NoneType
                 value=
-                '\ntest\n    ',  # str
+                '\n    test\n    ',  # str
             )  # /Constant
         )  # /Expr
         orelse=
         test=
         Constant(

Expected behavior

Black ignores the ACL change because docstrings are an exception

@Anonymous941 Anonymous941 added the T: bug Something isn't working label Apr 12, 2024
@hauntsaninja
Copy link
Collaborator

hauntsaninja commented Apr 12, 2024

Thanks, this was fixed in #4290 (regression in #4270)

Maybe we should cut a release... will release 24.4.0 #4307

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants