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

Crash on format comments and staticmethod #2029

Closed
AA-Turner opened this issue Mar 9, 2021 · 3 comments
Closed

Crash on format comments and staticmethod #2029

AA-Turner opened this issue Mar 9, 2021 · 3 comments
Labels
C: invalid code Black destroyed a valid Python file T: bug Something isn't working

Comments

@AA-Turner
Copy link

Describe the bug

Black crashes when run with the input below, I was asked to report a bug. Searched issues for staticmethod and I wasn't able to find a duplicate bug.

To Reproduce Steps to reproduce the behavior:

Run black on the following minimal reproducer:

class A:
    def f(self):
        # fmt: off
        pass
        # fmt: an

    @staticmethod
    def g():
        pass

Expected behavior Not to crash!

Does this bug also happen on master?

Tried on black.now.sh and got the same error. Link: https://black.now.sh/?version=master&state=_Td6WFoAAATm1rRGAgAhARYAAAB0L-Wj4ADPAHVdAD2IimZxl1N_WlXnON2nzNApqtITJJee2SMStFF7KJQ8b8DURX_4mSWuyzahm7XyRnFJw4Xsk-T0s6r9WQ1aWsFX30SYGTYIsr7er5h3jUgBMQ57uo6Vc7Nk2Ne4nD8I-8B1sA_8mxK9s2PHSQ37LUEOhsaewAAAAAB48B9ldZJwDgABkQHQAQAAJeuZD7HEZ_sCAAAAAARZWg==

Additional context Add any other context about the problem here.

Error log/diff:
--- src
+++ dst
@@ -25,44 +25,44 @@
                 None,  # NoneType
             )  # /arguments
           body=
             Pass(
             )  # /Pass
+            FunctionDef(
+              args=
+                arguments(
+                  args=
+                  defaults=
+                  kw_defaults=
+                  kwarg=
+                    None,  # NoneType
+                  kwonlyargs=
+                  posonlyargs=
+                  vararg=
+                    None,  # NoneType
+                )  # /arguments
+              body=
+                Pass(
+                )  # /Pass
+              decorator_list=
+                Name(
+                  ctx=
+                    Load(
+                    )  # /Load
+                  id=
+                    'staticmethod',  # str
+                )  # /Name
+              name=
+                'g',  # str
+              returns=
+                None,  # NoneType
+              type_comment=
+                None,  # NoneType
+            )  # /FunctionDef
           decorator_list=
           name=
             'f',  # str
-          returns=
-            None,  # NoneType
-          type_comment=
-            None,  # NoneType
-        )  # /FunctionDef
-        FunctionDef(
-          args=
-            arguments(
-              args=
-              defaults=
-              kw_defaults=
-              kwarg=
-                None,  # NoneType
-              kwonlyargs=
-              posonlyargs=
-              vararg=
-                None,  # NoneType
-            )  # /arguments
-          body=
-            Pass(
-            )  # /Pass
-          decorator_list=
-            Name(
-              ctx=
-                Load(
-                )  # /Load
-              id=
-                'staticmethod',  # str
-            )  # /Name
-          name=
-            'g',  # str
           returns=
             None,  # NoneType
           type_comment=
             None,  # NoneType
         )  # /FunctionDef
@AA-Turner AA-Turner added the T: bug Something isn't working label Mar 9, 2021
@ichard26 ichard26 added the C: invalid code Black destroyed a valid Python file label Mar 9, 2021
@ichard26
Copy link
Collaborator

ichard26 commented Mar 9, 2021

Hey thanks for the bug report, but I'll be closing as it's a duplicate of #569.

@ichard26 ichard26 closed this as completed Mar 9, 2021
@AA-Turner
Copy link
Author

Sorry, must have missed that. Thanks!

@AA-Turner
Copy link
Author

Just realised after re-reading that I typed an with an A not on - sorry for the noise. Will keep an eye on #1817.

Thanks for maintaining Black!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: invalid code Black destroyed a valid Python file T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants