aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/tools/python3/src/Lib/ast.py
diff options
context:
space:
mode:
authorshadchin <shadchin@yandex-team.com>2023-10-03 23:32:21 +0300
committershadchin <shadchin@yandex-team.com>2023-10-03 23:48:51 +0300
commit01ffd024041ac933854c367fb8d1b5682d19883f (patch)
treeb70aa497ba132a133ccece49f7763427dcd0743f /contrib/tools/python3/src/Lib/ast.py
parenta33fdb9a34581fd124e92535153b1f1fdeca6aaf (diff)
downloadydb-01ffd024041ac933854c367fb8d1b5682d19883f.tar.gz
Update Python 3 to 3.11.6
Diffstat (limited to 'contrib/tools/python3/src/Lib/ast.py')
-rw-r--r--contrib/tools/python3/src/Lib/ast.py18
1 files changed, 17 insertions, 1 deletions
diff --git a/contrib/tools/python3/src/Lib/ast.py b/contrib/tools/python3/src/Lib/ast.py
index 623b9a1b80..d84d75e1f3 100644
--- a/contrib/tools/python3/src/Lib/ast.py
+++ b/contrib/tools/python3/src/Lib/ast.py
@@ -1175,13 +1175,29 @@ class _Unparser(NodeVisitor):
new_fstring_parts = []
quote_types = list(_ALL_QUOTES)
+ fallback_to_repr = False
for value, is_constant in fstring_parts:
- value, quote_types = self._str_literal_helper(
+ value, new_quote_types = self._str_literal_helper(
value,
quote_types=quote_types,
escape_special_whitespace=is_constant,
)
new_fstring_parts.append(value)
+ if set(new_quote_types).isdisjoint(quote_types):
+ fallback_to_repr = True
+ break
+ quote_types = new_quote_types
+
+ if fallback_to_repr:
+ # If we weren't able to find a quote type that works for all parts
+ # of the JoinedStr, fallback to using repr and triple single quotes.
+ quote_types = ["'''"]
+ new_fstring_parts.clear()
+ for value, is_constant in fstring_parts:
+ value = repr('"' + value) # force repr to use single quotes
+ expected_prefix = "'\""
+ assert value.startswith(expected_prefix), repr(value)
+ new_fstring_parts.append(value[len(expected_prefix):-1])
value = "".join(new_fstring_parts)
quote_type = quote_types[0]