17.1.3 Queries on AST Objects

Two functions are provided which allow an application to determine if an AST was created as an expression or a suite. Neither of these functions can be used to determine if an AST was created from source code via expr() or suite() or from a parse tree via sequence2ast().

isexpr (ast)
When ast represents an 'eval' form, this function returns true, otherwise it returns false. This is useful, since code objects normally cannot be queried for this information using existing built-in functions. Note that the code objects created by compileast() cannot be queried like this either, and are identical to those created by the built-in compile() function.

issuite (ast)
This function mirrors isexpr() in that it reports whether an AST object represents an 'exec' form, commonly known as a ``suite.'' It is not safe to assume that this function is equivalent to "not isexpr(ast)", as additional syntactic fragments may be supported in the future.


Ver Sobre este documento... para obtener información sobre sugerencias.