Author vstinner
Recipients benjamin.peterson, matrixise, vstinner, yselivanov
Date 2015-11-05.09:42:03
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
I wrote an AST optimizer which build AST from source code using ast.parse(), modify AST in place, and then compile the AST to bytecode.

The problem is that the lineno and col_offset attributes of the "arg" AST node are uninitialized when AST is rebuild from Python objects: compile(ast_tree, ...). As a consequence, the compilation may fail because lineno or col_offset values are invalid.

Attached patch enhances Parser/ to take "arg" attributes in account. It also updates the generated files Include/Python-ast.h and Python/Python-ast.c, and fix usage of the arg() function in Python/ast.c.

It looks like only the "arg" AST node had attributes which were initialized (other AST nodes are handled with a different code path which already filled attributes).

See Parser/Python.asdl for the definition of the "arg" AST node.

Note: Python 2.7 is not affected. In Python 2, function arguments are simple expressions, they don't have a dedicated type with lineno and col_offset attributes. "arg" was introduced in Python 3 with the PEP 3107 (function annotations).
Date User Action Args
2015-11-05 09:42:05vstinnersetrecipients: + vstinner, benjamin.peterson, yselivanov, matrixise
2015-11-05 09:42:04vstinnersetmessageid: <>
2015-11-05 09:42:04vstinnerlinkissue25555 messages
2015-11-05 09:42:04vstinnercreate