Skip to content

Commit a13aaea

Browse files
committed
add test to test_fstring
1 parent f6fbb7e commit a13aaea

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Lib/test/test_fstring.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,12 @@
1212
import dis
1313
import os
1414
import re
15+
import tokenize
1516
import types
1617
import decimal
1718
import unittest
1819
import warnings
20+
from io import BytesIO
1921
from test import support
2022
from test.support.os_helper import temp_cwd
2123
from test.support.script_helper import assert_python_failure, assert_python_ok
@@ -1859,6 +1861,12 @@ def __format__(self, format):
18591861
# Test multiple format specs in same raw f-string
18601862
self.assertEqual(rf"{UnchangedFormat():\xFF} {UnchangedFormat():\n}", '\\xFF \\n')
18611863

1864+
def test_gh139516(self):
1865+
# gh-139516
1866+
# The '\n' is explicit to ensure no trailing whitespace which would invalidate the test.
1867+
# Must use tokenize instead of compile so that source is parsed by line which exposes the bug.
1868+
list(tokenize.tokenize(BytesIO('''f"{f(a=lambda: 'à'\n)}"'''.encode()).readline))
1869+
18621870

18631871
if __name__ == '__main__':
18641872
unittest.main()

0 commit comments

Comments
 (0)