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

Unnatural split on a line with a line-comment #1222

Closed
exhuma opened this issue Jan 7, 2020 · 1 comment
Closed

Unnatural split on a line with a line-comment #1222

exhuma opened this issue Jan 7, 2020 · 1 comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?

Comments

@exhuma
Copy link

exhuma commented Jan 7, 2020

Describe the style change

A line containing a type: ignore comment caused a really weird output. It has split an equality operation on the operator which looks very unnatural. Even though the line would fir well into the maximal line length making the split unnecessary.

It is probably easiest to see in the example below.

Examples in the current Black style Think of some short code snippets that show
how the current Black style is not great:

     def __eq__(self, other: Any) -> bool:
         if not isinstance(self, other.__class__):
             return False
 
-        return (self.device_ == other.device_ and  # type: ignore
-                self.scope == other.scope and
-                self.id == other.id)
+        return (
+            self.device_ == other.device_
+            and self.scope  # type: ignore
+            == other.scope
+            and self.id == other.id
+        )

Desired style How do you think Black should format the above snippets:

     def __eq__(self, other: Any) -> bool:
         if not isinstance(self, other.__class__):
             return False
 
-        return (self.device_ == other.device_ and  # type: ignore
-                self.scope == other.scope and
-                self.id == other.id)
+        return (
+            self.device_ == other.device_
+            and self.scope == other.scope  # type: ignore
+            and self.id == other.id
+        )
@exhuma exhuma added the T: style What do we want Blackened code to look like? label Jan 7, 2020
@JelleZijlstra JelleZijlstra added F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. F: linebreak How should we split up lines? labels May 30, 2021
@JelleZijlstra
Copy link
Collaborator

I am going to say this is another case of #379, which is generally about "Black reformatted the code and moved a comment to the wrong place".

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Apr 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: comments The syntactic kind. Not in the language grammar, always on our minds. Best bugs. F: linebreak How should we split up lines? T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants