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: compiler.parse("1;") adds unexpected extra Discard(Const(None)) to parse tree
Type: behavior Stage:
Components: Interpreter Core, Library (Lib) Versions: Python 2.6
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: dalke, gvanrossum, ncoghlan, nnorwitz
Priority: low Keywords:

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: Nick 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:30adminsetgithub: 46295
2008-02-05 11:48:35ncoghlansetstatus: open -> closed
resolution: wont fix
messages: + msg62067
2008-02-05 03:21:11dalkesetmessages: + msg62061
2008-02-05 01:46:23gvanrossumsetmessages: + msg62059
2008-02-05 01:36:21christian.heimessetpriority: low
nosy: + gvanrossum, nnorwitz, ncoghlan
components: + Interpreter Core
2008-02-05 00:46:41dalkecreate