@@ -2338,17 +2338,19 @@ def normalize_string_quotes(leaf: Leaf, single_quote: bool = False) -> None:
2338
2338
2339
2339
quote_char = '"'
2340
2340
alt_quote_char = "'"
2341
+ triple_quote_chars = '"""'
2342
+ alt_triple_quote_chars = "'''"
2341
2343
2342
2344
if single_quote :
2343
2345
quote_char = "'"
2344
2346
alt_quote_char = '"'
2345
2347
2346
- if value [:3 ] == ( quote_char * 3 ) :
2348
+ if value [:3 ] == triple_quote_chars :
2347
2349
return
2348
2350
2349
- elif value [:3 ] == ( alt_quote_char * 3 ) :
2350
- orig_quote = alt_quote_char * 3
2351
- new_quote = quote_char * 3
2351
+ elif value [:3 ] == alt_triple_quote_chars :
2352
+ orig_quote = alt_triple_quote_chars
2353
+ new_quote = triple_quote_chars
2352
2354
elif value [0 ] == quote_char :
2353
2355
orig_quote = quote_char
2354
2356
new_quote = alt_quote_char
@@ -2381,9 +2383,9 @@ def normalize_string_quotes(leaf: Leaf, single_quote: bool = False) -> None:
2381
2383
leaf .value = f"{ prefix } { orig_quote } { body } { orig_quote } "
2382
2384
new_body = sub_twice (escaped_orig_quote , rf"\1\2{ orig_quote } " , new_body )
2383
2385
new_body = sub_twice (unescaped_new_quote , rf"\1\\{ new_quote } " , new_body )
2384
- if new_quote == ( quote_char * 3 ) and new_body [- 1 ] == quote_char :
2386
+ if new_quote == triple_quote_chars and new_body [- 1 ] == triple_quote_chars [ 0 ] :
2385
2387
# edge case:
2386
- new_body = new_body [:- 1 ] + "\\ " + quote_char
2388
+ new_body = new_body [:- 1 ] + "\\ " + triple_quote_chars [ 0 ]
2387
2389
orig_escape_count = body .count ("\\ " )
2388
2390
new_escape_count = new_body .count ("\\ " )
2389
2391
if new_escape_count > orig_escape_count :
0 commit comments