From 7f3678885fc7ab6f9fb1749f6d2a8ed3468841f3 Mon Sep 17 00:00:00 2001 From: Zsolt Dollenstein Date: Thu, 7 Jun 2018 20:41:34 +0200 Subject: [PATCH] fix handling of empty triple quoted strings (#314) --- README.md | 1 + black.py | 2 +- tests/data/string_quotes.py | 2 ++ 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 411c9bf..580607f 100644 --- a/README.md +++ b/README.md @@ -813,6 +813,7 @@ More details can be found in [CONTRIBUTING](CONTRIBUTING.md). * fixed improper unmodified file caching when `-S` was used +* fixed formatting of empty triple quoted strings (#313) ### 18.6b1 diff --git a/black.py b/black.py index dd7fe39..1d2f1a3 100644 --- a/black.py +++ b/black.py @@ -2546,7 +2546,7 @@ def normalize_string_quotes(leaf: Leaf) -> None: leaf.value = f"{prefix}{orig_quote}{body}{orig_quote}" new_body = sub_twice(escaped_orig_quote, rf"\1\2{orig_quote}", new_body) new_body = sub_twice(unescaped_new_quote, rf"\1\\{new_quote}", new_body) - if new_quote == '"""' and new_body[-1] == '"': + if new_quote == '"""' and new_body[-1:] == '"': # edge case: new_body = new_body[:-1] + '\\"' orig_escape_count = body.count("\\") diff --git a/tests/data/string_quotes.py b/tests/data/string_quotes.py index 1ac6b06..807f866 100644 --- a/tests/data/string_quotes.py +++ b/tests/data/string_quotes.py @@ -1,3 +1,4 @@ +'''''' '\'' '"' "'" @@ -45,6 +46,7 @@ re.compile(r'[\\"]') # output +"""""" "'" '"' "'" -- 2.39.2