[Python-ideas] Retain string form of AST Numbers

Mark Dickinson dickinsm at gmail.com
Sat Apr 5 10:09:55 CEST 2014


On Sat, Apr 5, 2014 at 4:50 AM, Chris Angelico <rosuav at gmail.com> wrote:

> If the Num nodes also had a .str member with the unparsed string ("1",
> "2.000", and "3.0j"), it would be possible to influence their
> interpretation with an AST transform - for instance, turning them into
> decimal.Decimal construction calls, or wrapping them in something that
> automatically keeps track of significant figures (which would mean
> that "2.000" is considered more precise than a mere "2.0" or "2.").
>
> It shouldn't be too difficult to do, and it could simply be ignored in
> most cases; any sort of change to the actual number could leave the
> original string out of sync with it, which isn't a problem.
>
> Thoughts?
>

I like it. Apart from the AST transformation possibilities opened up, I
have some AST-based style checkers that would have benefited from access to
the raw numeric strings.

So as long as there's no significant adverse affect on total compilation
time or space requirements, +1 from me.

Mark
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/python-ideas/attachments/20140405/20d6a271/attachment-0001.html>


More information about the Python-ideas mailing list