Lib2to3 has its own parser and tree so it can reconstruct the file, with comments. AST JUST THROWS AWAY TOO MUCH.<br><br>On Saturday, April 5, 2014, Chris Angelico <<a href="mailto:rosuav@gmail.com">rosuav@gmail.com</a>> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">On Sun, Apr 6, 2014 at 3:39 AM, Serhiy Storchaka <<a href="javascript:;" onclick="_e(event, 'cvml', 'storchaka@gmail.com')">storchaka@gmail.com</a>> wrote:<br>
> What about strings?<br>
><br>
>>>> print(ast.dump(ast.parse(r"x = '''\x0a\u000d''' r'x'")))<br>
> Module(body=[Assign(targets=[Name(id='x', ctx=Store())],<br>
> value=Str(s='\n\rx'))])<br>
><br>
> Tuples?<br>
><br>
>>>> print(ast.dump(ast.parse("x = (1, 2,)")))<br>
> Module(body=[Assign(targets=[Name(id='x', ctx=Store())],<br>
> value=Tuple(elts=[Num(n=1), Num(n=2)], ctx=Load()))])<br>
<br>
I don't have any concrete use cases for those, but the same could be<br>
done for every type of node as a general mechanism for recreating a<br>
file more exactly. Nick linked to a tracker issue with some discussion<br>
on docstrings, which could benefit from that. Or maybe it would be<br>
better to avoid the AST altogether and do a source-level translation,<br>
as mentioned in the blog post he also linked to.<br>
<br>
ChrisA<br>
_______________________________________________<br>
Python-ideas mailing list<br>
<a href="javascript:;" onclick="_e(event, 'cvml', 'Python-ideas@python.org')">Python-ideas@python.org</a><br>
<a href="https://mail.python.org/mailman/listinfo/python-ideas" target="_blank">https://mail.python.org/mailman/listinfo/python-ideas</a><br>
Code of Conduct: <a href="http://python.org/psf/codeofconduct/" target="_blank">http://python.org/psf/codeofconduct/</a><br>
</blockquote><br><br>-- <br>--Guido van Rossum (on iPad)<br>