Author JBernardo
Recipients JBernardo, benjamin.peterson, daniel.urban, mark.dickinson
Date 2012-07-05.15:48:04
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1341503285.8.0.0409777709765.issue15245@psf.upfronthosting.co.za>
In-reply-to
Content
Of course `nan` and `inf` are part of the syntax! The `ast.parse` function recognize them as `Name`. 

So that works:

>>> ast.dump(ast.parse('True'))
"Module(body=[Expr(value=Name(id='True', ctx=Load()))])"

>>> ast.dump(ast.parse('inf'))
"Module(body=[Expr(value=Name(id='inf', ctx=Load()))])"

>>> inf = float('inf')
>>> eval('inf')
inf

I've run into some literals with `Ellipsis` and `inf` and couldn't load them with literal_eval. That's why I'm proposing that.

The thing about `nan` and `inf` is because they are the *only* representations of float numbers produced by the interpreter that cannot be loaded.

Something like that could solve the problem keeping `literal_eval` safe and allowing other names:

ast.literal_eval('[1.0, 2.0, inf]', {'inf': float('inf')})
History
Date User Action Args
2012-07-05 15:48:05JBernardosetrecipients: + JBernardo, mark.dickinson, benjamin.peterson, daniel.urban
2012-07-05 15:48:05JBernardosetmessageid: <1341503285.8.0.0409777709765.issue15245@psf.upfronthosting.co.za>
2012-07-05 15:48:05JBernardolinkissue15245 messages
2012-07-05 15:48:04JBernardocreate