Whoops, caps lock error. Didn't mean to shout. :-)

On Saturday, April 5, 2014, Guido van Rossum <guido@python.org> wrote:
Lib2to3 has its own parser and tree so it can reconstruct the file, with comments. AST JUST THROWS AWAY TOO MUCH.

On Saturday, April 5, 2014, Chris Angelico <rosuav@gmail.com> wrote:
On Sun, Apr 6, 2014 at 3:39 AM, Serhiy Storchaka <storchaka@gmail.com> wrote:
> What about strings?
>
>>>> print(ast.dump(ast.parse(r"x = '''\x0a\u000d''' r'x'")))
> Module(body=[Assign(targets=[Name(id='x', ctx=Store())],
> value=Str(s='\n\rx'))])
>
> Tuples?
>
>>>> print(ast.dump(ast.parse("x = (1, 2,)")))
> Module(body=[Assign(targets=[Name(id='x', ctx=Store())],
> value=Tuple(elts=[Num(n=1), Num(n=2)], ctx=Load()))])

I don't have any concrete use cases for those, but the same could be
done for every type of node as a general mechanism for recreating a
file more exactly. Nick linked to a tracker issue with some discussion
on docstrings, which could benefit from that. Or maybe it would be
better to avoid the AST altogether and do a source-level translation,
as mentioned in the blog post he also linked to.

ChrisA
_______________________________________________
Python-ideas mailing list
Python-ideas@python.org
https://mail.python.org/mailman/listinfo/python-ideas
Code of Conduct: http://python.org/psf/codeofconduct/


--
--Guido van Rossum (on iPad)


--
--Guido van Rossum (on iPad)