Issue #28512: Fixed setting the offset attribute of SyntaxError by

PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
This commit is contained in:
Serhiy Storchaka 2016-12-11 14:39:01 +02:00
parent 49c14d8e8f
commit 8b58339eb2
7 changed files with 56 additions and 58 deletions

View file

@ -148,15 +148,17 @@ class SymtableTest(unittest.TestCase):
def test_filename_correct(self):
### Bug tickler: SyntaxError file name correct whether error raised
### while parsing or building symbol table.
def checkfilename(brokencode):
def checkfilename(brokencode, offset):
try:
symtable.symtable(brokencode, "spam", "exec")
except SyntaxError as e:
self.assertEqual(e.filename, "spam")
self.assertEqual(e.lineno, 1)
self.assertEqual(e.offset, offset)
else:
self.fail("no SyntaxError for %r" % (brokencode,))
checkfilename("def f(x): foo)(") # parse-time
checkfilename("def f(x): global x") # symtable-build-time
checkfilename("def f(x): foo)(", 14) # parse-time
checkfilename("def f(x): global x", 10) # symtable-build-time
symtable.symtable("pass", b"spam", "exec")
with self.assertRaises(TypeError):
symtable.symtable("pass", bytearray(b"spam"), "exec")