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:
Serhiy Storchaka 2018-10-21 10:09:39 +03:00 committed by GitHub
parent 2f73ed6913
commit d31e7730cd
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 42 additions and 11 deletions

View file

@ -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