Call hierarchy for Python

Answered

I am using com.jetbrains.python.hierarchy.call.PyStaticCallHierarchyUtil#getCallees method to get the callees of a function.

However, I'm getting some weird results.

For this code snippet:

class A:
def __init__(self):
...

def foo(self, x):
return x


class B(A):
def foo(self, x):
return D()


class D(A):
def foo(self, x):
b = B()
b.foo(x)
return A()


class C(A):
def foo(self, x):
y = D()
y.foo(x)
return self


def driver():
x = A()
i = 10
while i > 0:
x = x.foo(B())

I want to know the callees of D.foo. According to my observation, there should be only two callees of D.foo:

  1. B.foo and
  2. A.__init__

But PyStaticCallHierarchyUtil#getCallees returns 5 callees for D.foo. I also checked in the PyCharm IDE, same results there as well.

Clearly, the type of b in b = B() is class B.

def foo(self, x):
b = B()
b.foo(x)
return A()

So, how come A.foo, C.foo, and D.foo are on the callee list of D.foo?

I would really appreciate any insight on this topic.

1 comment
Comment actions Permalink
Official comment

Hi, it is a bug. The fix is ready and should land in 2021.3.1, I've created a ticket in our bug tracker to track the status https://youtrack.jetbrains.com/issue/PY-52034

Please sign in to leave a comment.