Issue 2011: compiler.parse("1;") adds unexpected extra Discard(Const(None)) to parse tree (original) (raw)

Issue2011

Created on 2008-02-05 00:46 by dalke, last changed 2022-04-11 14:56 by admin. This issue is now closed.

Messages (4)
msg62057 - (view) Author: Andrew Dalke (dalke) * (Python committer) Date: 2008-02-05 00:46
Python 2.6a0 (trunk:60565M, Feb 4 2008, 01:21:28) [GCC 4.0.1 (Apple Computer, Inc. build 5367)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> from compiler import parse >>> parse("1;") Module(None, Stmt([Discard(Const(1)), Discard(Const(None))])) I did not expect the Discard(Const(None)). Instead, I expected Module(None, Stmt([Discard(Const(1))]))
msg62059 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2008-02-05 01:46
What on earth is this about?
msg62061 - (view) Author: Andrew Dalke (dalke) * (Python committer) Date: 2008-02-05 03:21
This really is a minor point. I don't track the 3K list and I see now that the compiler module won't be in Python 3k - good riddance - so feel free to discard this as well as the other open compiler module bugs. I want to experiment with adding instrumentation for branch coverage. To do that I want to get the character ranges of each term in the AST. The Python compiler module doesn't keep track of that so I'm developing a new parser based on PLY. I've developed it and I'm now cross-checking the generated ASTs to verify they are identical. In this case the compiler module generates an extra node in the AST so I had to add backwards compatibility support.
msg62067 - (view) Author: Alyssa Coghlan (ncoghlan) * (Python committer) Date: 2008-02-05 11:48
Marking this as Won't Fix. I'd suggest looking at the _ast module (http://docs.python.org/dev/library/_ast.html) as a reference rather than the compiler module. The maintenance on the latter has been sketchy at best, and as you note, it is scheduled for a well earned retirement in 3.0. Passing _ast.PyCF_ONLY_AST as a flag to the builtin function compile() will let you get an AST using the actual runtime compiler, so any odd nodes you find in there are likely to be there for a reason (e.g. None is implicitly inserted into most function namespaces due to the implied 'return None' at the end of the function).
History
Date User Action Args
2022-04-11 14:56:30 admin set github: 46295
2008-02-05 11:48:35 ncoghlan set status: open -> closedresolution: wont fixmessages: +
2008-02-05 03:21:11 dalke set messages: +
2008-02-05 01:46:23 gvanrossum set messages: +
2008-02-05 01:36:21 christian.heimes set priority: lownosy: + gvanrossum, nnorwitz, ncoghlancomponents: + Interpreter Core
2008-02-05 00:46:41 dalke create