[IPython-dev] AST transformations - ready for review

Aaron Meurer asmeurer@gmail....
Sat Sep 29 18:07:08 CDT 2012


I noted this on the pull request too, but in case anyone reads it
here, the code for that transformer is wrong.  It should be

class IntegerWrapper(ast.NodeTransformer):
    """Wraps all integers in a call to Integer()"""
    def visit_Num(self, node):
        if isinstance(node.n, int):
            return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()),
                            args=[node], keywords=[])
        return node


Otherwise, it will fail for expressions containing floating point numbers.

Aaron Meurer

On Sat, Sep 29, 2012 at 3:22 AM, Thomas Kluyver <takowl@gmail.com> wrote:
> Hi all,
>
> I think the AST transformation hook in PR #2301 is ready for review.
> https://github.com/ipython/ipython/pull/2301
>
> I've made sure that it works with %timeit, %time and macros. I've also
> added a test for the Integer() wrapper that Sage and Sympy both want
> to apply. The code for that is:
>
> class IntegerWrapper(ast.NodeTransformer):
>     """Wraps all integers in a call to Integer()"""
>     def visit_Num(self, node):
>         if isinstance(node.n, int):
>             return ast.Call(func=ast.Name(id='Integer', ctx=ast.Load()),
>                             args=[node], keywords=[])
>
>
> Thanks,
> Thomas
> _______________________________________________
> IPython-dev mailing list
> IPython-dev@scipy.org
> http://mail.scipy.org/mailman/listinfo/ipython-dev


More information about the IPython-dev mailing list