gh-127975: Avoid reusing quote types in ast.unparse if not needed (#127980)

This commit is contained in:
Shantanu 2025-01-31 00:49:06 -08:00 committed by GitHub
parent 95504f429e
commit 8df5193d37
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 15 additions and 7 deletions

View file

@ -1196,9 +1196,14 @@ class _Unparser(NodeVisitor):
fallback_to_repr = True
break
quote_types = new_quote_types
elif "\n" in value:
quote_types = [q for q in quote_types if q in _MULTI_QUOTES]
assert quote_types
else:
if "\n" in value:
quote_types = [q for q in quote_types if q in _MULTI_QUOTES]
assert quote_types
new_quote_types = [q for q in quote_types if q not in value]
if new_quote_types:
quote_types = new_quote_types
new_fstring_parts.append(value)
if fallback_to_repr: