fix handling of empty triple quoted strings (#314)

This commit is contained in:
Zsolt Dollenstein 2018-06-07 20:41:34 +02:00 committed by Łukasz Langa
parent 75a9447448
commit 7f3678885f
3 changed files with 4 additions and 1 deletions

View File

@ -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

View File

@ -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("\\")

View File

@ -1,3 +1,4 @@
''''''
'\''
'"'
"'"
@ -45,6 +46,7 @@
# output
""""""
"'"
'"'
"'"