[issue25885] ast Str type does not annotate the string type when it parses a python document

STINNER Victor report at bugs.python.org
Wed Dec 16 17:25:54 EST 2015


STINNER Victor added the comment:

"There would be a huge benefit to having accurate original syntax information of the document and being able to re-write the documents as it would enable self modifying code or software written code paradigms."

You misunderstood the purpose of the AST tree. "Unparse" AST to retrieve the original source code is out of the scope of the Python AST structure and it's not going to happen. For that, you must use other tool. See for example RedBaron, as I said at:

http://bugs.python.org/issue25886#msg256543

Being able to "unparse" AST to regenerate the Python original source code requires complex operation. You have to store all formating information (spaces, new lines, etc.). You also have to store comments. It's just to give a few examples.

If AST contains formating information, it would be more complex to handle AST.

----------
nosy: +haypo

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue25885>
_______________________________________


More information about the Python-bugs-list mailing list