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

Inconsistent code formatting error #1978

Closed
whs opened this issue Feb 9, 2021 · 2 comments
Closed

Inconsistent code formatting error #1978

whs opened this issue Feb 9, 2021 · 2 comments
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

@whs
Copy link

whs commented Feb 9, 2021

Black v20.8b1

Playground link

Options

--line-length=88
--safe

Input

if True:
    pass
elif feature in (QWebEnginePage.DesktopVideoCapture, QWebEnginePage.DesktopAudioVideoCapture) and self.app.has_permission('pixel'):
    pass

Output

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_t3rp1oih.log

Mode(target_versions=set(), line_length=88, string_normalization=True, experimental_string_processing=False, is_pyi=False)
--- source
+++ first pass
@@ -1,4 +1,7 @@
 if True:
     pass
-elif feature in (QWebEnginePage.DesktopVideoCapture, QWebEnginePage.DesktopAudioVideoCapture) and self.app.has_permission('pixel'):
+elif feature in (
+    QWebEnginePage.DesktopVideoCapture,
+    QWebEnginePage.DesktopAudioVideoCapture,
+) and self.app.has_permission("pixel"):
     pass
--- first pass
+++ second pass
@@ -1,7 +1,11 @@
 if True:
     pass
-elif feature in (
-    QWebEnginePage.DesktopVideoCapture,
-    QWebEnginePage.DesktopAudioVideoCapture,
-) and self.app.has_permission("pixel"):
+elif (
+    feature
+    in (
+        QWebEnginePage.DesktopVideoCapture,
+        QWebEnginePage.DesktopAudioVideoCapture,
+    )
+    and self.app.has_permission("pixel")
+):
     pass

Expected

If I write it by hand I'd prefer

if True:
    pass
elif (
    feature in (
        QWebEnginePage.DesktopVideoCapture,
        QWebEnginePage.DesktopAudioVideoCapture
    )
    and self.app.has_permission('pixel')
):
    pass

The code is from https://github.com/whs/runekit/blob/master/runekit/app/view/browser_window.py

@ichard26 ichard26 added T: bug Something isn't working C: unstable formatting Formatting changed on the second pass labels Feb 10, 2021
@mvolfik
Copy link

mvolfik commented Feb 22, 2021

This is a duplicate of #1629 , as the short sample works after applying #1958. However, when I take the full file, black still fails. I'll report in the #1629 thread and suggest closing this.

EDIT: Nevermind, I got lost in my black virtualenvs, the whole file works after applying that patch too.

@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Apr 25, 2021
@ichard26
Copy link
Collaborator

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

3 participants