Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't generate code containing ast.Num(NaN) #85

Closed
Kodiologist opened this issue Nov 1, 2017 · 3 comments
Closed

Can't generate code containing ast.Num(NaN) #85

Kodiologist opened this issue Nov 1, 2017 · 3 comments

Comments

@Kodiologist
Copy link
Contributor

Kodiologist commented Nov 1, 2017

Somewhat related to #82, the codegen of astor 0.5 would produce nan if given a Num node that contained NaN. In astor 0.6, the following raises an AssertionError in code_gen.py:

import ast, astor

nan = 1e1000 - 1e1000

print(astor.code_gen.to_source(
         ast.Module([ast.Expr(ast.BinOp(
             ast.Num(1.0),
             ast.Add(),
             ast.Num(nan)))])))

While Python has no NaN literal, you could represent ast.Num(nan) as an expression (such as 1e1000 - 1e1000) if you want to generate real Python. See hylang/hy#1447.

@pmaupin
Copy link
Collaborator

pmaupin commented Nov 1, 2017

We can add this if someone submits a PR, but of course, it won't round-trip AST -> Python -> AST properly, so any test for this will have to special-case this.

@berkerpeksag
Copy link
Owner

@Kodiologist I'm planning to release 0.7.0 this weekend and I can merge a fix for this if you still need it for Hy.

@Kodiologist
Copy link
Contributor Author

It would be convenient, but it's not necessary. I worked around the issue in Hy commit a074bb9a5c3 by replacing NaN with such expressions in the compiler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants