This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: parsermodule validation out of sync with Grammar
Type: behavior Stage:
Components: Library (Lib) Versions: Python 3.0
process
Status: closed Resolution: accepted
Dependencies: Superseder:
Assigned To: gvanrossum Nosy List: christian.heimes, dbinger, fdrake, gvanrossum
Priority: low Keywords: patch

Created on 2007-09-11 11:05 by dbinger, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (7)
msg55818 - (view) Author: David Binger (dbinger) Date: 2007-09-11 11:05
>>> parser.sequence2st(parser.suite("class A(object): pass").tolist())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
parser.ParserError: Expected node type 326, got 329.

---

The Grammar in python 3 uses "arglist" instead of "testlist"
for class definitions.  The parsermodule's validate_class()
calls validate_testlist() where it should now be calling
validate_arglist().
msg57243 - (view) Author: Christian Heimes (christian.heimes) * (Python committer) Date: 2007-11-08 13:57
It's still breaking but Guido should know how to fix the parser.
msg57288 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-09 00:24
No, I didn't write the parser module (which isn't the parser, just a
wrapper to make it accessible from Python).
msg57526 - (view) Author: David Binger (dbinger) Date: 2007-11-15 11:46
The one line patch below makes
"import parser; parser.sequence2st(parser.suite("class A(object): 
pass").tolist())"
work.  It puts the parsermodule's validation back in sync
with the Python3 grammar for this rule of the grammar.

This bug is a serious problem for me.

Index: Modules/parsermodule.c
===================================================================
--- Modules/parsermodule.c	(revision 58978)
+++ Modules/parsermodule.c	(working copy)
@@ -992,7 +992,7 @@
     if (res) {
 	if (nch == 7) {
 		res = ((validate_lparen(CHILD(tree, 2)) &&
-			validate_testlist(CHILD(tree, 3)) &&
+			validate_arglist(CHILD(tree, 3)) &&
 			validate_rparen(CHILD(tree, 4))));
 	}
 	else if (nch == 6) {
msg57539 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-15 17:29
Can you submit a unittest that catches this? Then I can check in the fix.
msg57549 - (view) Author: David Binger (dbinger) Date: 2007-11-15 18:50
Okay, here is the whole thing with a unittest that exposes the problem.

Index: Lib/test/test_parser.py
===================================================================
--- Lib/test/test_parser.py     (revision 58984)
+++ Lib/test/test_parser.py     (working copy)
@@ -136,6 +136,7 @@
 
     def test_class_defs(self):
         self.check_suite("class foo():pass")
+        self.check_suite("class foo(object):pass")
 
     def test_import_from_statement(self):
         self.check_suite("from sys.path import *")
Index: Modules/parsermodule.c
===================================================================
--- Modules/parsermodule.c      (revision 58984)
+++ Modules/parsermodule.c      (working copy)
@@ -992,7 +992,7 @@
     if (res) {
        if (nch == 7) {
                res = ((validate_lparen(CHILD(tree, 2)) &&
-                       validate_testlist(CHILD(tree, 3)) &&
+                       validate_arglist(CHILD(tree, 3)) &&
                        validate_rparen(CHILD(tree, 4))));
        }
        else if (nch == 6) {
msg57550 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2007-11-15 19:17
Committed revision 58987.
History
Date User Action Args
2022-04-11 14:56:26adminsetgithub: 45485
2007-11-15 19:17:39gvanrossumsetstatus: open -> closed
messages: + msg57550
2007-11-15 18:50:29dbingersetmessages: + msg57549
2007-11-15 17:29:33gvanrossumsetassignee: fdrake -> gvanrossum
messages: + msg57539
2007-11-15 11:46:13dbingersetmessages: + msg57526
2007-11-09 00:24:51gvanrossumsetassignee: gvanrossum -> fdrake
messages: + msg57288
nosy: + fdrake
2007-11-08 13:57:06christian.heimessetnosy: + gvanrossum, christian.heimes
messages: + msg57243
priority: normal -> low
assignee: gvanrossum
keywords: + patch
resolution: accepted
2007-09-17 09:53:58jafosetpriority: normal
2007-09-11 11:05:31dbingercreate