Closed
Description
Bug report
Running python -m test test_fstring
on main
results in several SyntaxWarnings
being emitted.
If I just run python -m test test_fstring
locally, I get this:
C:\Users\alexw\coding\cpython>python -m test test_fstring
Running Release|x64 interpreter...
0:00:00 Run tests sequentially
0:00:00 [1/1] test_fstring
C:\Users\alexw\coding\cpython\Lib\test\test_fstring.py:775: SyntaxWarning: invalid escape sequence '\_'
exec('f"{F():¯\_(ツ)_/¯}"', {'F': CustomFormat})
== Tests result: SUCCESS ==
1 test OK.
Total duration: 14.5 sec
Tests result: SUCCESS
If I run python -We -m test test_fstring -vv
, I get a different selection of SyntaxWarnings:
======================================================================
ERROR: test_fstring_backslash_before_double_bracket (test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket) (case="f'\\{{\\}}'", expected_result='\\{\\}')
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_fstring.py", line 1041, in test_fstring_backslash_before_double_bracket
result = eval(case)
^^^^^^^^^^
File "<string>", line 1
f'\{{\}}'
^
SyntaxError: invalid escape sequence '\{'
======================================================================
ERROR: test_fstring_backslash_before_double_bracket (test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket) (case="f'\\{{'", expected_result='\\{')
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_fstring.py", line 1041, in test_fstring_backslash_before_double_bracket
result = eval(case)
^^^^^^^^^^
File "<string>", line 1
f'\{{'
^
SyntaxError: invalid escape sequence '\{'
======================================================================
ERROR: test_fstring_backslash_before_double_bracket (test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket) (case="f'\\{{{1+1}'", expected_result='\\{2')
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_fstring.py", line 1041, in test_fstring_backslash_before_double_bracket
result = eval(case)
^^^^^^^^^^
File "<string>", line 1
f'\{{{1+1}'
^
SyntaxError: invalid escape sequence '\{'
======================================================================
ERROR: test_fstring_backslash_before_double_bracket (test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket) (case="f'\\}}{1+1}'", expected_result='\\}2')
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_fstring.py", line 1041, in test_fstring_backslash_before_double_bracket
result = eval(case)
^^^^^^^^^^
File "<string>", line 1
f'\}}{1+1}'
^
SyntaxError: invalid escape sequence '\}'
======================================================================
ERROR: test_fstring_backslash_before_double_bracket (test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket) (case="f'{1+1}\\}}'", expected_result='2\\}')
----------------------------------------------------------------------
Traceback (most recent call last):
File "C:\Users\alexw\coding\cpython\Lib\test\test_fstring.py", line 1041, in test_fstring_backslash_before_double_bracket
result = eval(case)
^^^^^^^^^^
File "<string>", line 1
f'{1+1}\}}'
^
SyntaxError: invalid escape sequence '\}'
----------------------------------------------------------------------
Ran 80 tests in 14.399s
FAILED (errors=5)
test test_fstring failed
test_fstring failed (5 errors)
== Tests result: FAILURE ==
1 test failed:
test_fstring
Total duration: 14.6 sec
Tests result: FAILURE
Your environment
Python 3.13.0a0 (heads/main:ab3823a97b, Jun 19 2023, 14:46:42) [MSC v.1932 64 bit (AMD64)] on win32
Linked PRs
- gh-105915: Add 'r' prefix to not emit SyntaxWarning in test_fstring #105940
- [3.12] gh-105915: Add 'r' prefix to not emit SyntaxWarning in test_fstring (GH-105940) #105942
- gh-105915: Fix SyntaxWarning becoming a SyntaxError with -We in test_fstring #105943
- [3.12] gh-105915: Fix SyntaxWarning becoming a SyntaxError with -We in test_fstring (GH-105943) #105945