mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
This commit is contained in:
commit
26817a8490
8 changed files with 56 additions and 60 deletions
|
@ -548,7 +548,7 @@ from test import support
|
|||
class SyntaxTestCase(unittest.TestCase):
|
||||
|
||||
def _check_error(self, code, errtext,
|
||||
filename="<testcase>", mode="exec", subclass=None):
|
||||
filename="<testcase>", mode="exec", subclass=None, lineno=None, offset=None):
|
||||
"""Check that compiling code raises SyntaxError with errtext.
|
||||
|
||||
errtest is a regular expression that must be present in the
|
||||
|
@ -563,6 +563,11 @@ class SyntaxTestCase(unittest.TestCase):
|
|||
mo = re.search(errtext, str(err))
|
||||
if mo is None:
|
||||
self.fail("SyntaxError did not contain '%r'" % (errtext,))
|
||||
self.assertEqual(err.filename, filename)
|
||||
if lineno is not None:
|
||||
self.assertEqual(err.lineno, lineno)
|
||||
if offset is not None:
|
||||
self.assertEqual(err.offset, offset)
|
||||
else:
|
||||
self.fail("compile() did not raise SyntaxError")
|
||||
|
||||
|
@ -573,7 +578,7 @@ class SyntaxTestCase(unittest.TestCase):
|
|||
self._check_error("del f()", "delete")
|
||||
|
||||
def test_global_err_then_warn(self):
|
||||
# Bug tickler: The SyntaxError raised for one global statement
|
||||
# Bug #763201: The SyntaxError raised for one global statement
|
||||
# shouldn't be clobbered by a SyntaxWarning issued for a later one.
|
||||
source = """if 1:
|
||||
def error(a):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue