Hi

To be able to work around false positive errors in my code, I'd like to
improve the type inference to support code having this form:
    assert isinstance(foo_var, bar_type)

So that from that point on in the local context the variable for_var would
have the type bar_type inferred, which is the one used in practice.

So I took a look at pylint and astng. From what I understand, I'd need to
connect with astng.node_classes.Assert to add type inference but I didn't
fine a specific "isinstance" node.

-- foo.py --
class A: pass
def B(x): assert isinstance(x, A)
-- end --

from logilab.astng import builder
tree = builder.ASTNGBuilder().file_build('foo.py')
print ', '.join(str(n) for n in tree.body)
# Class(A), Function(B)
print ', '.join(str(n) for n in tree.body[1].body)
# Assert()
dir(tree.body[1].body[0])
# This node as no body.
print ', '.join(str(n) for n in tree.body[1].body)
# CallFunc()

And that's the problem I see, astng sees "isinstance" as a normal CallFunc()
node instead of a specialized node (?) So should
astng._nodes_compiler.TreeRebuilder.visit_callfunc() look for 'isinstance'
and return a specialized node so afterward type inference could be improved?
I just started to look at this this morning to I have limited knowledge.

I think I'd be fine with implementing the functionality but I'm still a bit
lost so I'd need guidance.

M-A
_______________________________________________
Python-Projects mailing list
[email protected]
http://lists.logilab.org/mailman/listinfo/python-projects

Reply via email to