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)

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).


Comment actions Permalink

Even this snippet as in  :

final TypeEvalContext context = TypeEvalContext.codeAnalysis(project, file);
final PyResolveContext resolveContext = PyResolveContext.defaultContext().withTypeEvalContext(context);

List<PyCallableType> callableTypes = node.multiResolveCallee(resolveContext);

doesn't yield correct result.

Comment actions Permalink

I tried this snippet on the callee as PyReferenceExpression:

@NotNull ResolveResult[] elements = node.getReference().multiResolve(false);

Works way better, but sometimes gives duplicated results like when resolving


I get 2 results with same #getElement.

Is this the best way possible?


Comment actions Permalink

Do the object IDs of returned elements also match?

Comment actions Permalink


@NotNull ResolveResult[] elements = node.getReference().multiResolve(false);

Yes, they match. Is it the correct way to resolve PyReferenceExpression?

I suppose then the TypeEvalContextPyResolveContext are used for general Find Usage?


Please sign in to leave a comment.