summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/test/test_tokenize.py20
-rw-r--r--Lib/tokenize.py2
-rw-r--r--Misc/NEWS.d/next/Core_and_Builtins/2024-10-05-23-53-06.gh-issue-125008.ETANpd.rst2
3 files changed, 23 insertions, 1 deletions
diff --git a/Lib/test/test_tokenize.py b/Lib/test/test_tokenize.py
index de0e0b4..75710db 100644
--- a/Lib/test/test_tokenize.py
+++ b/Lib/test/test_tokenize.py
@@ -1919,6 +1919,26 @@ class TestRoundtrip(TestCase):
self.check_roundtrip(r"f'\\\\N{{'")
self.check_roundtrip(r"f'\\\\\\N{{'")
self.check_roundtrip(r"f'\\\\\\\\N{{'")
+
+ self.check_roundtrip(r"f'\n{{foo}}'")
+ self.check_roundtrip(r"f'\\n{{foo}}'")
+ self.check_roundtrip(r"f'\\\n{{foo}}'")
+ self.check_roundtrip(r"f'\\\\n{{foo}}'")
+
+ self.check_roundtrip(r"f'\t{{foo}}'")
+ self.check_roundtrip(r"f'\\t{{foo}}'")
+ self.check_roundtrip(r"f'\\\t{{foo}}'")
+ self.check_roundtrip(r"f'\\\\t{{foo}}'")
+
+ self.check_roundtrip(r"rf'\t{{foo}}'")
+ self.check_roundtrip(r"rf'\\t{{foo}}'")
+ self.check_roundtrip(r"rf'\\\t{{foo}}'")
+ self.check_roundtrip(r"rf'\\\\t{{foo}}'")
+
+ self.check_roundtrip(r"rf'\{{foo}}'")
+ self.check_roundtrip(r"f'\\{{foo}}'")
+ self.check_roundtrip(r"rf'\\\{{foo}}'")
+ self.check_roundtrip(r"f'\\\\{{foo}}'")
cases = [
"""
if 1:
diff --git a/Lib/tokenize.py b/Lib/tokenize.py
index 7f418bb..4b4c3cf 100644
--- a/Lib/tokenize.py
+++ b/Lib/tokenize.py
@@ -200,7 +200,7 @@ class Untokenizer:
characters[-2::-1]
)
)
- if n_backslashes % 2 == 0:
+ if n_backslashes % 2 == 0 or characters[-1] != "N":
characters.append(character)
else:
consume_until_next_bracket = True
diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2024-10-05-23-53-06.gh-issue-125008.ETANpd.rst b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-05-23-53-06.gh-issue-125008.ETANpd.rst
new file mode 100644
index 0000000..8971e05
--- /dev/null
+++ b/Misc/NEWS.d/next/Core_and_Builtins/2024-10-05-23-53-06.gh-issue-125008.ETANpd.rst
@@ -0,0 +1,2 @@
+Fix :func:`tokenize.untokenize` producing invalid syntax for
+double braces preceded by certain escape characters.