mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
bpo-35029: Replace the SyntaxWarning exception with a SyntaxError. (GH-9999)
If SyntaxWarning was raised as an exception, it will be replaced with a SyntaxError for better error reporting.
This commit is contained in:
parent
2f73ed6913
commit
d31e7730cd
3 changed files with 42 additions and 11 deletions
|
@ -5,6 +5,7 @@ from test.support import check_syntax_error
|
|||
import inspect
|
||||
import unittest
|
||||
import sys
|
||||
import warnings
|
||||
# testing import *
|
||||
from sys import *
|
||||
|
||||
|
@ -1099,6 +1100,14 @@ class GrammarTests(unittest.TestCase):
|
|||
else:
|
||||
self.fail("AssertionError not raised by 'assert False'")
|
||||
|
||||
with self.assertWarnsRegex(SyntaxWarning, 'assertion is always true'):
|
||||
compile('assert(x, "msg")', '<testcase>', 'exec')
|
||||
with warnings.catch_warnings():
|
||||
warnings.filterwarnings('error', category=SyntaxWarning)
|
||||
with self.assertRaisesRegex(SyntaxError, 'assertion is always true'):
|
||||
compile('assert(x, "msg")', '<testcase>', 'exec')
|
||||
compile('assert x, "msg"', '<testcase>', 'exec')
|
||||
|
||||
|
||||
### compound_stmt: if_stmt | while_stmt | for_stmt | try_stmt | funcdef | classdef
|
||||
# Tested below
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue