João Bernardo <jbv...@gmail.com> added the comment: 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')}) ---------- _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue15245> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com