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

Inconsistance in numerical node behavior #65

Closed
remram44 opened this issue Apr 20, 2015 · 4 comments
Closed

Inconsistance in numerical node behavior #65

remram44 opened this issue Apr 20, 2015 · 4 comments

Comments

@remram44
Copy link
Contributor

As far as I know, number literals can be one of IntNode, FloatNode, OctaNode, HexaNode, LongNode. However they don't appear in the code or doc, except for IntNode, which works differently because its value is a number instead of str.

So I'm left with:

def get_int_value(node):
    NUMBERS = IntNode, FloatNode, OctaNode, HexaNode, LongNode

    if isinstance(node, NUMBERS):
        if isinstance(node, IntNode):
            return node.value
        else:
            return ast.literal_eval(node.value)
    else:
        raise ValueError

code = RedBaron('a = 12\na = 0xC')
get_int_value(code[0].assign.value), get_int_value(code[1].assign.value)
@Psycojoker Psycojoker changed the title Integer literal node types Inconsistance in numerical node behavior May 2, 2015
@Psycojoker
Copy link
Member

Hello,

Yes, this is bad, I think that I'm going to switch back to string everywhere and providing a .to_python() method that does a ast.literal.

Thanks for reporting,

@remram44
Copy link
Contributor Author

remram44 commented May 2, 2015

Awesome! That'd be great, thanks!

@Psycojoker
Copy link
Member

@remram44
Copy link
Contributor Author

I'll be using that!

remram44 added a commit to VisTrails/VisTrails that referenced this issue May 28, 2015
remram44 added a commit to VisTrails/VisTrails that referenced this issue Jun 15, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants