X-Git-Url: https://git.madduck.net/etc/vim.git/blobdiff_plain/cb5aadad74c0a1c9c514a633c632c99b668c70ed..cf8e998f46e89da39fa64029cc4550e2862f7ec2:/black.py?ds=sidebyside diff --git a/black.py b/black.py index 3e3ae0a..9581d63 100644 --- a/black.py +++ b/black.py @@ -1998,6 +1998,9 @@ def normalize_string_quotes(leaf: Leaf) -> None: else: new_body = escaped_orig_quote.sub(rf"\1{orig_quote}", body) new_body = unescaped_new_quote.sub(rf"\1\\{new_quote}", new_body) + # Add escapes again for consecutive occurences of new_quote (sub + # doesn't match overlapping substrings). + new_body = unescaped_new_quote.sub(rf"\1\\{new_quote}", new_body) if new_quote == '"""' and new_body[-1] == '"': # edge case: new_body = new_body[:-1] + '\\"' @@ -2088,14 +2091,16 @@ def max_delimiter_priority_in_atom(node: LN) -> int: first = node.children[0] last = node.children[-1] - if first.type == token.LPAR and last.type == token.RPAR: - bt = BracketTracker() - for c in node.children[1:-1]: - if isinstance(c, Leaf): - bt.mark(c) - else: - for leaf in c.leaves(): - bt.mark(leaf) + if not (first.type == token.LPAR and last.type == token.RPAR): + return 0 + + bt = BracketTracker() + for c in node.children[1:-1]: + if isinstance(c, Leaf): + bt.mark(c) + else: + for leaf in c.leaves(): + bt.mark(leaf) try: return bt.max_delimiter_priority()