Giter Site home page Giter Site logo

Comments (8)

vitsalis avatar vitsalis commented on May 24, 2024

PyCG should produce a complete call graph in this case. This is probably a bug with the generator, I'll investigate when I got the bandwidth and get back to you.

from pycg.

LeeSureman avatar LeeSureman commented on May 24, 2024

Very thank you for your quick response!! It will be a great help for me. Actually I can provide another code snippet which may be related to the code above or an extension (about external library) of the code above. This code sample is as following:

def f_sample_2():
    import numpy
    import torch

    numpy_array = numpy.ones(shape=[2,3])
    torch_tensor = torch.ones(size=[2,3])

    numpy_array.max()
    torch_tensor.max()

The extracted callgraph is
["numpy.ones", "torch.ones"]
I think it maybe lack
numpy.ndarray.max and torch.Tensor.max (Am I right? or is it within expectation? )

this new case involves the external library like numpy and torch. (I see your code involves handling external library, so in expectation your code can give the complete callgraph in this case?)
Looking forward to receiving your response.

from pycg.

seanxiaoyan avatar seanxiaoyan commented on May 24, 2024

Hello, I have read your work "PyCG: Practical Call Graph Generation in Python", and think it is valuable, helpful and insightful. However, when I try to scan this file as following:

class tmp_C:
    def tmp_f_in_c(self):
        print('tmp_f_in_c called')
        return None

def tmp_f():
    a = tmp_C
    returned = a()
    return returned


def f_sample():

    tmp_c = tmp_f()
    tmp_c.tmp_f_in_c()

the extracted callgraph is {"small": ["small.f_sample"], "small.tmp_C.tmp_f_in_c": ["<builtin>.print"], "<builtin>.print": [], "small.tmp_f": [], "small.f_sample": ["small.tmp_f"]} there is not 'small.tmp_C.tmp_f_in_c' in 'small.f_sample' 's calling function while 'small.f_sample' has called 'small.tmp_C.tmp_f_in_c'. So I'd ask whether your callgraph generator could extract this complete callgraph within expectation? It will be a great and wonderful help if you response me. Thank you!

I think PyCG is trying to look for class tmp_c but tmp_c is not defined anywhere in scope.
It will work if you change tmp_c.tmp_f_in_c() to tmp_C.tmp_f_in_c()

{"small": [], "small.tmp_C.tmp_f_in_c": ["<builtin>.print"], "<builtin>.print": [], "small.tmp_f": [], "small.f_sample": ["small.tmp_f", "small.tmp_C.tmp_f_in_c"]}

from pycg.

LeeSureman avatar LeeSureman commented on May 24, 2024

Hello, I have read your work "PyCG: Practical Call Graph Generation in Python", and think it is valuable, helpful and insightful. However, when I try to scan this file as following:

class tmp_C:
    def tmp_f_in_c(self):
        print('tmp_f_in_c called')
        return None

def tmp_f():
    a = tmp_C
    returned = a()
    return returned


def f_sample():

    tmp_c = tmp_f()
    tmp_c.tmp_f_in_c()

the extracted callgraph is {"small": ["small.f_sample"], "small.tmp_C.tmp_f_in_c": ["<builtin>.print"], "<builtin>.print": [], "small.tmp_f": [], "small.f_sample": ["small.tmp_f"]} there is not 'small.tmp_C.tmp_f_in_c' in 'small.f_sample' 's calling function while 'small.f_sample' has called 'small.tmp_C.tmp_f_in_c'. So I'd ask whether your callgraph generator could extract this complete callgraph within expectation? It will be a great and wonderful help if you response me. Thank you!

I think PyCG is trying to look for class tmp_c but tmp_c is not defined anywhere in scope. It will work if you change tmp_c.tmp_f_in_c() to tmp_C.tmp_f_in_c()

{"small": [], "small.tmp_C.tmp_f_in_c": ["<builtin>.print"], "<builtin>.print": [], "small.tmp_f": [], "small.f_sample": ["small.tmp_f", "small.tmp_C.tmp_f_in_c"]}

Thank you for your response and help!
Since 'tmp_c' is the instance of 'tmp_C' as defined in 'tmp_f', do you mean PYCG technically can not detect 'tmp_c' is the instance of 'tmp_C'?

from pycg.

seanxiaoyan avatar seanxiaoyan commented on May 24, 2024

Hello, I have read your work "PyCG: Practical Call Graph Generation in Python", and think it is valuable, helpful and insightful. However, when I try to scan this file as following:

class tmp_C:
    def tmp_f_in_c(self):
        print('tmp_f_in_c called')
        return None

def tmp_f():
    a = tmp_C
    returned = a()
    return returned


def f_sample():

    tmp_c = tmp_f()
    tmp_c.tmp_f_in_c()

the extracted callgraph is {"small": ["small.f_sample"], "small.tmp_C.tmp_f_in_c": ["<builtin>.print"], "<builtin>.print": [], "small.tmp_f": [], "small.f_sample": ["small.tmp_f"]} there is not 'small.tmp_C.tmp_f_in_c' in 'small.f_sample' 's calling function while 'small.f_sample' has called 'small.tmp_C.tmp_f_in_c'. So I'd ask whether your callgraph generator could extract this complete callgraph within expectation? It will be a great and wonderful help if you response me. Thank you!

I think PyCG is trying to look for class tmp_c but tmp_c is not defined anywhere in scope. It will work if you change tmp_c.tmp_f_in_c() to tmp_C.tmp_f_in_c()

{"small": [], "small.tmp_C.tmp_f_in_c": ["<builtin>.print"], "<builtin>.print": [], "small.tmp_f": [], "small.f_sample": ["small.tmp_f", "small.tmp_C.tmp_f_in_c"]}

Thank you for your response and help! Since 'tmp_c' is the instance of 'tmp_C' as defined in 'tmp_f', do you mean PYCG technically can not detect 'tmp_c' is the instance of 'tmp_C'?

This is causing issue

    a = tmp_C
    returned = a()

PyCG can detect instance if the code looks like this

class tmp_C:
    def tmp_f_in_c(self):
        print('tmp_f_in_c called')
        return None

def tmp_f():
    a = tmp_C()
    return a


def f_sample():
    tmp_c = tmp_f()
    tmp_c.tmp_f_in_c()

from pycg.

LeeSureman avatar LeeSureman commented on May 24, 2024

@seanxiaoyan yes, it is rare but it is grammatical in python.. Since the author says PYCG should detect it, I will wait for him to figure out it..

from pycg.

LeeSureman avatar LeeSureman commented on May 24, 2024

hello, would you mind me asking when this bug can be fixed?

from pycg.

vitsalis avatar vitsalis commented on May 24, 2024

Closing due to archival of repository.

from pycg.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.