mirror of
https://github.com/python/cpython.git
synced 2025-10-21 22:22:48 +00:00
bpo-36440: include node names in ParserError messages, instead of numeric IDs (GH-12565)
The error messages in the parser module are referring to numeric IDs for the nodes. To improve readability, use the node names when reporting errors.
This commit is contained in:
parent
76b387bf74
commit
cb0748d393
3 changed files with 29 additions and 6 deletions
|
@ -749,6 +749,22 @@ class IllegalSyntaxTestCase(unittest.TestCase):
|
|||
with self.assertRaises(UnicodeEncodeError):
|
||||
parser.sequence2st(tree)
|
||||
|
||||
def test_invalid_node_id(self):
|
||||
tree = (257, (269, (-7, '')))
|
||||
self.check_bad_tree(tree, "negative node id")
|
||||
tree = (257, (269, (99, '')))
|
||||
self.check_bad_tree(tree, "invalid token id")
|
||||
tree = (257, (269, (9999, (0, ''))))
|
||||
self.check_bad_tree(tree, "invalid symbol id")
|
||||
|
||||
def test_ParserError_message(self):
|
||||
try:
|
||||
parser.sequence2st((257,(269,(257,(0,'')))))
|
||||
except parser.ParserError as why:
|
||||
self.assertIn("compound_stmt", str(why)) # Expected
|
||||
self.assertIn("file_input", str(why)) # Got
|
||||
|
||||
|
||||
|
||||
class CompileTestCase(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue