]> git.madduck.net Git - etc/vim.git/blobdiff - black.py

madduck's git repository

Every one of the projects in this repository is available at the canonical URL git://git.madduck.net/madduck/pub/<projectpath> — see each project's metadata for the exact URL.

All patches and comments are welcome. Please squash your changes to logical commits before using git-format-patch and git-send-email to patches@git.madduck.net. If you'd read over the Git project's submission guidelines and adhered to them, I'd be especially grateful.

SSH access, as well as push access can be individually arranged.

If you use my repositories frequently, consider adding the following snippet to ~/.gitconfig and using the third clone URL listed for each project:

[url "git://git.madduck.net/madduck/"]
  insteadOf = madduck:

Removing empty parentheses after class name (#180)
[etc/vim.git] / black.py
index f235afe60c7aa3545a16fd96c0e8d7a9459fa72b..cfb5028d68d85be324c450838f7797ecbe22e5fd 100644 (file)
--- a/black.py
+++ b/black.py
@@ -743,6 +743,9 @@ class Line:
         if not has_value:
             return
 
+        if token.COLON == leaf.type and self.is_class_parenth_empty:
+            del self.leaves[-2:]
+
         if self.leaves and not preformatted:
             # Note: at this point leaf.prefix should be empty except for
             # imports, for which we only preserve newlines.
@@ -840,6 +843,19 @@ class Line:
             and self.leaves[0].value == "yield"
         )
 
+    @property
+    def is_class_parenth_empty(self) -> bool:
+        """Is this class parentheses blank?"""
+        return (
+            bool(self)
+            and len(self.leaves) == 4
+            and self.is_class
+            and self.leaves[2].type == token.LPAR
+            and self.leaves[2].value == "("
+            and self.leaves[3].type == token.RPAR
+            and self.leaves[3].value == ")"
+        )
+
     def contains_standalone_comments(self, depth_limit: int = sys.maxsize) -> bool:
         """If so, needs to be split before emitting."""
         for leaf in self.leaves:
@@ -1125,6 +1141,7 @@ class LineGenerator(Visitor[Line]):
 
         If any lines were generated, set up a new current_line.
         """
+
         if not self.current_line:
             if self.current_line.__class__ == type:
                 self.current_line.depth += indent