summaryrefslogtreecommitdiffstats
path: root/Lib/ast.py
diff options
context:
space:
mode:
authorShantanu <12621235+hauntsaninja@users.noreply.github.com>2025-01-31 08:49:06 (GMT)
committerGitHub <noreply@github.com>2025-01-31 08:49:06 (GMT)
commit8df5193d37f70a1478642c4b456dcc7d6df6c117 (patch)
treee81c499c63bab25018ac819ba7b67cbb123220a6 /Lib/ast.py
parent95504f429eec04010d0b815345ebcc3af2402af0 (diff)
downloadcpython-8df5193d37f70a1478642c4b456dcc7d6df6c117.zip
cpython-8df5193d37f70a1478642c4b456dcc7d6df6c117.tar.gz
cpython-8df5193d37f70a1478642c4b456dcc7d6df6c117.tar.bz2
gh-127975: Avoid reusing quote types in ast.unparse if not needed (#127980)
Diffstat (limited to 'Lib/ast.py')
-rw-r--r--Lib/ast.py11
1 files changed, 8 insertions, 3 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index 154d2c8..0937c27 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -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: