problems with using the Compiler module

Robert Brewer fumanchu at amor.org
Sat Feb 21 22:18:36 CET 2004


Stephen Emslie wrote:
> I am wanting to create a simple code inspector and the Compiler module
> seems to be a good starting point. However there seems to be either a
> problem with the module, or with the way that I'm using it.
> 
> once I get the AST, I want to traverse the tree pulling out certain
> information. For this I wanted to use node.getType() to deal with a
> specific type of node correctly.
> 
> But all that node.getType() ever returns is None. Is this method
> depreciated? If not then why will it only return None?

getType() is a method of compiler.ast.Node. Looking at the source (lines
37-40 in mine):

class Node: # an abstract base class
    lineno = None # provide a lineno for nodes that don't have one
    def getType(self):
        pass # implemented by subclass

...unfortunately for you, none of the subclasses of Node in compiler.ast
override getType(). So getType() returns None just like any other method
without an explicit return value.

If you want to traverse the tree, look at the docs and source for
compiler.visitor


Robert Brewer
MIS
Amor Ministries
fumanchu at amor.org




More information about the Python-list mailing list