koknat / callGraph

A multi-language tool which parses source code for function definitions and calls
GNU General Public License v3.0
230 stars 27 forks source link

[Python] functions with the same name but different classes #18

Closed eric3119 closed 1 year ago

eric3119 commented 1 year ago

it is currently not possible to differentiate methods with the same name but from different classes in the same file.

Example:

class ClassA:
    def method_name(self):
        return 0

class ClassB:
    def method_name(self):
        return 0

if __name__ == '__main__':
    ClassA.method_name()
    ClassB.method_name()

callGraph output:

{
    "teste/multiple_functions.py:method_name": {
        "called_by": {
            "teste/multiple_functions.py:__MAIN__": 1
        }
    },
    "teste/multiple_functions.py:__MAIN__": {
        "calls": {
            "teste/multiple_functions.py:method_name": 1
        }
    }
}
koknat commented 1 year ago

I agree. It's a practical limitation of this script having only one parser to support a wide range of languages. I'd recommend using a Python-only call graph generator instead.