On Fri, Apr 24, 2015 at 5:52 AM, Jarrad Hope
apologies for double email,
I was looking into inference and it looks like theres some context required for inference? specifically function argument types?
The context is also used for optimization, because it has a cache of inferred objects. next(node.infer(context=InferenceContext()) should be enough for start.
I tried next(node.infer()) and iterating through the infer generator but all i can seem to muster is a "YES/_Yes" object I looked in source and unit tests but it's not clear what YES means
YES node represents something that wasn't inferrable at a given time. To explain better through an example. Let's say we have a module, called missing, which doesn't exist at all anywhere. Trying to infer the x from this code will lead to an YES, meaning that astroid knows something is there, but can't know what. from missing import Missing x = Missing()
I see test_infer_arguments, which seems to test inference of function arguments based on their calls, it it possible to infer arguments based on their interaction with locals?
for example def double(x): return(x * 2)
What you need here is a call context (see astroid.bases.CallContext). All by itself, that x is nothing more than a YES node, but if you provide a call context, than you can reach something more useful. Here's an example of how the inference is actually getting to a result: from astroid.builder import AstroidBuilder b = AstroidBuilder() node = b.string_build(''' def test(x): return x*2 f = test(3) ''') f = node['f'] result = next(f.infer()) print(result) # Const print(result.value) # it finds out that's actually 6
I'd like to be able to walk the double function arguments and infer x is an int based on it's interaction with Const(int)