mirror of
https://github.com/python/cpython.git
synced 2025-10-10 00:43:41 +00:00
Issue #28512: Fixed setting the offset attribute of SyntaxError by
PyErr_SyntaxLocationEx() and PyErr_SyntaxLocationObject().
This commit is contained in:
parent
49c14d8e8f
commit
8b58339eb2
7 changed files with 56 additions and 58 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue