How to properly resolve a PyCallExpression
class Vector2(object):
def __init__(self, x, y):
self.x = x
self.y = y
def method(self):
print("hello function!")
vector2 = Vector2(-1, -2)
vector2.method()
Considering this simple snippet when trying to resolve the PyCallExpression "method" like this: (in PyRecursiveElementVisitor.visitPyCallExpression(PyCallExpression node))
List<PyCallableType> callableTypes = node.multiResolveCallee(PyResolveContext.defaultContext());
I get an empty list, but when I use: (in PyRecursiveElementVisitor.visitPyCallExpression(PyCallExpression node))
List<PyCallableType> callableTypes = node.multiResolveCallee(PyResolveContext.implicitContext());
I get a list of multiple elements (11 occurences, one of them is the actual result).
How to tell which element is the most accurate one giving this simple case with explicit usage.
How actually IntelliJ handles Go To Declaration? Because it automatically jumps to the declaration when it is trivial (no errors, and access is explicit without getattr or setattr).
Thanks.
Please sign in to leave a comment.
Even this snippet as in https://github.com/JetBrains/intellij-community/blob/master/python/testSrc/com/jetbrains/python/PyResolveCalleeTest.java :
doesn't yield correct result.
I tried this snippet on the callee as PyReferenceExpression:
Works way better, but sometimes gives duplicated results like when resolving
I get 2 results with same #getElement.
Is this the best way possible?
Thanks.
Do the object IDs of returned elements also match?
For:
Yes, they match. Is it the correct way to resolve PyReferenceExpression?
I suppose then the TypeEvalContext, PyResolveContext are used for general Find Usage?