X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/2593af2c5d211b58e28f7c1472f1f67e6783216a..257d392217974a76231e306133288748c7b70786:/src/black/nodes.py diff --git a/src/black/nodes.py b/src/black/nodes.py index ef42278..45423b2 100644 --- a/src/black/nodes.py +++ b/src/black/nodes.py @@ -714,6 +714,11 @@ def is_multiline_string(leaf: Leaf) -> bool: def is_stub_suite(node: Node) -> bool: """Return True if `node` is a suite with a stub body.""" + + # If there is a comment, we want to keep it. + if node.prefix.strip(): + return False + if ( len(node.children) != 4 or node.children[0].type != token.NEWLINE @@ -722,6 +727,9 @@ def is_stub_suite(node: Node) -> bool: ): return False + if node.children[3].prefix.strip(): + return False + return is_stub_body(node.children[2]) @@ -735,7 +743,8 @@ def is_stub_body(node: LN) -> bool: child = node.children[0] return ( - child.type == syms.atom + not child.prefix.strip() + and child.type == syms.atom and len(child.children) == 3 and all(leaf == Leaf(token.DOT, ".") for leaf in child.children) )