X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/cf6f577928f5a1f4e98b02b8e723311cae830305..7e1c5b2ba6355f1a6916cf5545dc577cf2e6c727:/black.py diff --git a/black.py b/black.py index 7ca6bc6..53d332a 100644 --- a/black.py +++ b/black.py @@ -320,6 +320,15 @@ class DebugVisitor(Visitor[T]): out(f' {node.prefix!r}', fg='green', bold=False, nl=False) out(f' {node.value!r}', fg='blue', bold=False) + @classmethod + def show(cls, code: str) -> None: + """Pretty-prints a given string of `code`. + + Convenience method for debugging. + """ + v: DebugVisitor[None] = DebugVisitor() + list(v.visit(lib2to3_parse(code))) + KEYWORDS = set(keyword.kwlist) WHITESPACE = {token.DEDENT, token.INDENT, token.NEWLINE} @@ -1183,7 +1192,7 @@ def make_comment(content: str) -> str: if content[0] == '#': content = content[1:] - if content and content[0] not in {' ', '!', '#'}: + if content and content[0] not in ' !:#': content = ' ' + content return '#' + content