X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/9f096d55365cb63548eef97e254c2793ae2776a0..6dbb657681b82268f66bd788991a4daa737577dc:/black.py?ds=sidebyside diff --git a/black.py b/black.py index 5e087d1..cfb5028 100644 --- a/black.py +++ b/black.py @@ -1,5 +1,3 @@ -#!/usr/bin/env python3 - import asyncio import pickle from asyncio.base_events import BaseEventLoop @@ -194,6 +192,7 @@ def main( write_back = WriteBack.YES report = Report(check=check, quiet=quiet) if len(sources) == 0: + out("No paths given. Nothing to do 😴") ctx.exit(0) return @@ -744,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. @@ -841,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: @@ -1126,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