diff options
author | Tomas R. <tomas.roun8@gmail.com> | 2024-10-06 13:16:41 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-10-06 13:16:41 (GMT) |
commit | db23b8bb13863fcd88ff91bc22398f8e0312039e (patch) | |
tree | 249ab119c5555e2fc487882f37969cca96a9e7d1 /Lib | |
parent | 39c859f6ffd8dee7f48b2181c6cb59cffe8125ff (diff) | |
download | cpython-db23b8bb13863fcd88ff91bc22398f8e0312039e.zip cpython-db23b8bb13863fcd88ff91bc22398f8e0312039e.tar.gz cpython-db23b8bb13863fcd88ff91bc22398f8e0312039e.tar.bz2 |
gh-125008: Fix `tokenize.untokenize` roundtrip for `\n{{` (#125013)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_tokenize.py | 20 | ||||
-rw-r--r-- | Lib/tokenize.py | 2 |
2 files changed, 21 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 |