mirror of
https://github.com/python/cpython.git
synced 2025-11-01 14:11:41 +00:00
[3.14] gh-139640: Fix swallowing syntax warnings in different modules (GH-139755) (GH-140117)
Revert GH-131993.
Fix swallowing some syntax warnings in different modules if they accidentally
have the same message and are emitted from the same line.
Fix duplicated warnings in the "finally" block.
(cherry picked from commit 279db6bede)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
* Update 2025-10-06-10-03-37.gh-issue-139640.gY5oTb.rst
---------
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
This commit is contained in:
parent
99e42ab49c
commit
af28efd8b4
7 changed files with 63 additions and 74 deletions
|
|
@ -1,7 +1,6 @@
|
|||
import contextlib
|
||||
import io
|
||||
import unittest
|
||||
import warnings
|
||||
from unittest.mock import patch
|
||||
from textwrap import dedent
|
||||
|
||||
|
|
@ -274,28 +273,3 @@ def test_incomplete_statement(self):
|
|||
code = "if foo:"
|
||||
console = InteractiveColoredConsole(namespace, filename="<stdin>")
|
||||
self.assertTrue(_more_lines(console, code))
|
||||
|
||||
|
||||
class TestWarnings(unittest.TestCase):
|
||||
def test_pep_765_warning(self):
|
||||
"""
|
||||
Test that a SyntaxWarning emitted from the
|
||||
AST optimizer is only shown once in the REPL.
|
||||
"""
|
||||
# gh-131927
|
||||
console = InteractiveColoredConsole()
|
||||
code = dedent("""\
|
||||
def f():
|
||||
try:
|
||||
return 1
|
||||
finally:
|
||||
return 2
|
||||
""")
|
||||
|
||||
with warnings.catch_warnings(record=True) as caught:
|
||||
warnings.simplefilter("default")
|
||||
console.runsource(code)
|
||||
|
||||
count = sum("'return' in a 'finally' block" in str(w.message)
|
||||
for w in caught)
|
||||
self.assertEqual(count, 1)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue