Skip to content

SyntaxWarnings in test_fstring #105915

Closed
Closed
@AlexWaygood

Description

@AlexWaygood

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

Metadata

Metadata

Labels

easytestsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions