https://github.com/python/cpython/commit/83479c217523c277cccb9db1e214d99b1c9d6343
commit: 83479c217523c277cccb9db1e214d99b1c9d6343
branch: main
author: Irit Katriel <[email protected]>
committer: iritkatriel <[email protected]>
date: 2025-03-18T12:33:46Z
summary:
gh-130080: fix warnings in tests (#131400)
files:
M Lib/test/test_compile.py
M Lib/test/test_functools.py
M Lib/test/test_grammar.py
M Lib/test/test_sys_settrace.py
M Lib/test/test_unparse.py
M Lib/test/test_yield_from.py
diff --git a/Lib/test/test_compile.py b/Lib/test/test_compile.py
index f5d757d8fc72c9..b1dc770fe4d411 100644
--- a/Lib/test/test_compile.py
+++ b/Lib/test/test_compile.py
@@ -2415,7 +2415,9 @@ def compile_snippet(i):
script = """def func():\n""" + i * snippet
if async_:
script = "async " + script
- code = compile(script, "<script>", "exec")
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', SyntaxWarning)
+ code = compile(script, "<script>", "exec")
exec(code, ns, ns)
return ns['func'].__code__
diff --git a/Lib/test/test_functools.py b/Lib/test/test_functools.py
index 5e04b15e014ea2..fe096fa075865f 100644
--- a/Lib/test/test_functools.py
+++ b/Lib/test/test_functools.py
@@ -3011,7 +3011,8 @@ def cls_context_manager(cls, arg: int) -> str:
try:
yield str(arg)
finally:
- return 'Done'
+ pass
+ return 'Done'
@classmethod_friendly_decorator
@classmethod
@@ -3027,7 +3028,8 @@ def cls_context_manager(cls, arg: int) -> str:
try:
yield str(arg)
finally:
- return 'Done'
+ pass
+ return 'Done'
@functools.singledispatchmethod
@classmethod_friendly_decorator
diff --git a/Lib/test/test_grammar.py b/Lib/test/test_grammar.py
index 994c8a0e15ac40..bde0b45b3ceb93 100644
--- a/Lib/test/test_grammar.py
+++ b/Lib/test/test_grammar.py
@@ -917,56 +917,59 @@ def g3():
check_syntax_error(self, "class foo:return 1")
def test_break_in_finally(self):
- count = 0
- while count < 2:
- count += 1
- try:
- pass
- finally:
- break
- self.assertEqual(count, 1)
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', SyntaxWarning)
- count = 0
- while count < 2:
- count += 1
- try:
- continue
- finally:
- break
- self.assertEqual(count, 1)
+ count = 0
+ while count < 2:
+ count += 1
+ try:
+ pass
+ finally:
+ break
+ self.assertEqual(count, 1)
- count = 0
- while count < 2:
- count += 1
- try:
- 1/0
- finally:
- break
- self.assertEqual(count, 1)
+ count = 0
+ while count < 2:
+ count += 1
+ try:
+ continue
+ finally:
+ break
+ self.assertEqual(count, 1)
- for count in [0, 1]:
+ count = 0
+ while count < 2:
+ count += 1
+ try:
+ 1/0
+ finally:
+ break
+ self.assertEqual(count, 1)
+
+ for count in [0, 1]:
+ self.assertEqual(count, 0)
+ try:
+ pass
+ finally:
+ break
self.assertEqual(count, 0)
- try:
- pass
- finally:
- break
- self.assertEqual(count, 0)
- for count in [0, 1]:
+ for count in [0, 1]:
+ self.assertEqual(count, 0)
+ try:
+ continue
+ finally:
+ break
self.assertEqual(count, 0)
- try:
- continue
- finally:
- break
- self.assertEqual(count, 0)
- for count in [0, 1]:
+ for count in [0, 1]:
+ self.assertEqual(count, 0)
+ try:
+ 1/0
+ finally:
+ break
self.assertEqual(count, 0)
- try:
- 1/0
- finally:
- break
- self.assertEqual(count, 0)
def test_continue_in_finally(self):
count = 0
diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py
index e528c6a9c69d28..b3685a91c57ee7 100644
--- a/Lib/test/test_sys_settrace.py
+++ b/Lib/test/test_sys_settrace.py
@@ -920,20 +920,28 @@ def test_try_except_with_wrong_type(self):
def func():
try:
- 2/0
- except IndexError:
- 4
- finally:
- return 6
+ try:
+ 2/0
+ except IndexError:
+ 5
+ finally:
+ 7
+ except:
+ pass
+ return 10
self.run_and_compare(func,
[(0, 'call'),
(1, 'line'),
(2, 'line'),
- (2, 'exception'),
(3, 'line'),
- (6, 'line'),
- (6, 'return')])
+ (3, 'exception'),
+ (4, 'line'),
+ (7, 'line'),
+ (8, 'line'),
+ (9, 'line'),
+ (10, 'line'),
+ (10, 'return')])
def test_finally_with_conditional(self):
@@ -2228,21 +2236,6 @@ def test_jump_in_nested_finally_3(output):
output.append(11)
output.append(12)
- @jump_test(5, 11, [2, 4], (ValueError, 'comes after the current code
block'))
- def test_no_jump_over_return_try_finally_in_finally_block(output):
- try:
- output.append(2)
- finally:
- output.append(4)
- output.append(5)
- return
- try:
- output.append(8)
- finally:
- output.append(10)
- pass
- output.append(12)
-
@jump_test(3, 4, [1], (ValueError, 'after'))
def test_no_jump_infinite_while_loop(output):
output.append(1)
@@ -2766,7 +2759,7 @@ def test_no_jump_over_return_out_of_finally_block(output):
finally:
output.append(4)
output.append(5)
- return
+ return
output.append(7)
@jump_test(7, 4, [1, 6], (ValueError, 'into'))
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index 9efea1e037f447..686649a520880e 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -5,6 +5,7 @@
import pathlib
import random
import tokenize
+import warnings
import ast
from test.support.ast_helper import ASTTestMixin
@@ -839,13 +840,16 @@ def files_to_test(cls):
return items
def test_files(self):
- for item in self.files_to_test():
- if test.support.verbose:
- print(f"Testing {item.absolute()}")
+ with warnings.catch_warnings():
+ warnings.simplefilter('ignore', SyntaxWarning)
- with self.subTest(filename=item):
- source = read_pyfile(item)
- self.check_ast_roundtrip(source)
+ for item in self.files_to_test():
+ if test.support.verbose:
+ print(f"Testing {item.absolute()}")
+
+ with self.subTest(filename=item):
+ source = read_pyfile(item)
+ self.check_ast_roundtrip(source)
if __name__ == "__main__":
diff --git a/Lib/test/test_yield_from.py b/Lib/test/test_yield_from.py
index b90e15e20027dc..06edc18df14944 100644
--- a/Lib/test/test_yield_from.py
+++ b/Lib/test/test_yield_from.py
@@ -1520,8 +1520,9 @@ def inner():
try:
yield yielded_first
yield yielded_second
- finally:
- return returned
+ except:
+ pass
+ return returned
def outer():
return (yield from inner())
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]