Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SyntaxWarnings in test_fstring #105915

Closed
AlexWaygood opened this issue Jun 19, 2023 · 8 comments
Closed

SyntaxWarnings in test_fstring #105915

AlexWaygood opened this issue Jun 19, 2023 · 8 comments
Assignees
Labels
easy tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error

Comments

@AlexWaygood
Copy link
Member

AlexWaygood commented Jun 19, 2023

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

@AlexWaygood AlexWaygood added type-bug An unexpected behavior, bug, or error tests Tests in the Lib/test dir labels Jun 19, 2023
@sunmy2019
Copy link
Member

The first should be

-            exec('f"{F():¯\_(ツ)_/¯}"', {'F': CustomFormat})
+            exec(r'f"{F():¯\_(ツ)_/¯}"', {'F': CustomFormat})

I am wondering why the second test is reporting errors.

@sobolevn
Copy link
Member

I cannot reproduce this locally on macOS (using 155577d), output for me:

» ./python.exe -m test test_fstring   
0:00:00 load avg: 1.06 Run tests sequentially
0:00:00 load avg: 1.06 [1/1] test_fstring

== Tests result: SUCCESS ==

1 test OK.

Total duration: 1.6 sec
Tests result: SUCCESS

@AlexWaygood
Copy link
Member Author

I cannot reproduce this locally on macOS (using 155577d), output for me:

» ./python.exe -m test test_fstring   
0:00:00 load avg: 1.06 Run tests sequentially
0:00:00 load avg: 1.06 [1/1] test_fstring

== Tests result: SUCCESS ==

1 test OK.

Total duration: 1.6 sec
Tests result: SUCCESS

I'm certain this reproduced consistently for me when I filed the report, but I can also no longer reproduce the first issue. I have no idea why this is.

I can still reproduce the test failures when running the test with -We, however.

@lysnikolaou
Copy link
Contributor

Related: #105938. Having a look.

lysnikolaou added a commit to lysnikolaou/cpython that referenced this issue Jun 20, 2023
miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 20, 2023
…ring (pythonGH-105940)

(cherry picked from commit 4b431d2)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: @sunmy2019
@lysnikolaou
Copy link
Contributor

Fixed in #105938 and #105940.

@lysnikolaou
Copy link
Contributor

I just now realize I could've left #105940 for any of the upcoming sprints, since it was an easy fix. Sorry for that! ❤️

@AlexWaygood
Copy link
Member Author

Hmm, even with a fresh build on main, I still get one failure when running python -We -m test test_fstring -v:

======================================================================
ERROR: test_fstring_backslash_before_double_bracket_warns_once (test.test_fstring.TestCase.test_fstring_backslash_before_double_bracket_warns_once)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "C:\Users\alexw\coding\cpython\Lib\test\test_fstring.py", line 1052, in test_fstring_backslash_before_double_bracket_warns_once
    eval(r"f'\{{'")
  File "<string>", line 1
    f'\{{'
       ^
SyntaxError: invalid escape sequence '\{'

----------------------------------------------------------------------
Ran 81 tests in 30.549s

FAILED (errors=1)
test test_fstring failed
test_fstring failed (1 error) in 30.7 sec

== Tests result: FAILURE ==

1 test failed:
    test_fstring

Total duration: 30.8 sec
Tests result: FAILURE

lysnikolaou added a commit that referenced this issue Jun 20, 2023
…tring (GH-105940) (#105942)

(cherry picked from commit 4b431d2)

Co-authored-by: @sunmy2019
Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
lysnikolaou added a commit to lysnikolaou/cpython that referenced this issue Jun 20, 2023
@lysnikolaou
Copy link
Contributor

Oops, that was the new test I added in #105939. Opened #105943.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue Jun 20, 2023
… test_fstring (pythonGH-105943)

(cherry picked from commit 6e40ee6)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
lysnikolaou added a commit that referenced this issue Jun 20, 2023
…n test_fstring (GH-105943) (#105945)

(cherry picked from commit 6e40ee6)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
easy tests Tests in the Lib/test dir type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

No branches or pull requests

6 participants