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

INTERNAL ERROR when formatting a function with a comment #2065

Closed
dcermak opened this issue Mar 26, 2021 · 1 comment
Closed

INTERNAL ERROR when formatting a function with a comment #2065

dcermak opened this issue Mar 26, 2021 · 1 comment
Labels
C: unstable formatting Formatting changed on the second pass R: duplicate This issue or pull request already exists T: bug Something isn't working

Comments

@dcermak
Copy link

dcermak commented Mar 26, 2021

Describe the bug

Black encounters an internal error when trying to format a function call with a comment before a parameter.

To Reproduce

  1. Take this file:
class TestPathToPosition:
    def test_path_after_blank_level(self):
        sls_start = MASTER_DOT_SLS[:position_to_index(MASTER_DOT_SLS, 8, 2)]
        assert construct_path_to_position(
            sls_start,
            # After the last character
            Position(line=8, character=2)
        ) == [
            "saltmaster.packages"
        ]
  1. Run Black on it:
$ python -m black fmt_error.py
error: cannot format fmt_error.py: INTERNAL ERROR: Black produced different code on the second pass of the formatter.  Please report a bug on https://github.com/psf/black/issues.  This diff might be helpful: /tmp/blk_l9gcdo5g.log
Oh no! 💥 💔 💥
1 file failed to reformat.

Expected behavior

Formatting should succeed

Environment (please complete the following information):

  • Version: latest from pypi
  • OS and Python version: Linux (Ubuntu, openSUSE Tumbleweed and Fedora 33), Python 3.8 and 3.9

Does this bug also happen on master?

yes (verified using https://black.now.sh/?version=master)

Additional context

  • removing the comment before Position makes the bug dissappear
  • contents of the diff:
Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,10 +1,8 @@
 class TestPathToPosition:
     def test_path_after_blank_level(self):
-        sls_start = MASTER_DOT_SLS[:position_to_index(MASTER_DOT_SLS, 8, 2)]
+        sls_start = MASTER_DOT_SLS[: position_to_index(MASTER_DOT_SLS, 8, 2)]
         assert construct_path_to_position(
             sls_start,
             # After the last character
-            Position(line=8, character=2)
-        ) == [
-            "saltmaster.packages"
-        ]
+            Position(line=8, character=2),
+        ) == ["saltmaster.packages"]
--- first pass
+++ second pass
@@ -1,8 +1,11 @@
 class TestPathToPosition:
     def test_path_after_blank_level(self):
         sls_start = MASTER_DOT_SLS[: position_to_index(MASTER_DOT_SLS, 8, 2)]
-        assert construct_path_to_position(
-            sls_start,
-            # After the last character
-            Position(line=8, character=2),
-        ) == ["saltmaster.packages"]
+        assert (
+            construct_path_to_position(
+                sls_start,
+                # After the last character
+                Position(line=8, character=2),
+            )
+            == ["saltmaster.packages"]
+        )
@dcermak dcermak added the T: bug Something isn't working label Mar 26, 2021
@ichard26 ichard26 added the C: unstable formatting Formatting changed on the second pass label Apr 1, 2021
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Apr 25, 2021
@ichard26
Copy link
Collaborator

ichard26 commented Apr 25, 2021

Hello!

All reproduction cases in this issue format without error on master. The fixing commit was 8672af3 from PR GH-2126. I'll be marking this issue as a duplicate of GH-1629 since that's what GH-2126 aimed to fix and it's highly likely this issue falls under GH-1629.

Since we use the issue tracker as a reflection of what's on master, I'll be closing this issue. If you have any issues, especially with the new (but stable) output, please open a new issue. Oh and the fix should be available in a published release soon, see GH-2125 for more info.

Thank you for reporting!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C: unstable formatting Formatting changed on the second pass 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