Skip to content

False Negative - Python abc.ABC makes method's getACall unavailable #18725

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
fubuki8087 opened this issue Feb 10, 2025 · 3 comments
Open

False Negative - Python abc.ABC makes method's getACall unavailable #18725

fubuki8087 opened this issue Feb 10, 2025 · 3 comments
Labels
question Further information is requested

Comments

@fubuki8087
Copy link

If we have this Python code:

class MyClass():
    def method(self):
        print("xxx")
    def wrapper(self):
        self.method()

mc = MyClass()
mc.method()

and this query:

import python

from PythonFunctionValue method
select method.getACall()

It's OK that self.method() and mc.method() will be marked as positive.

However, those will be false negative as long as the class MyClass inherits abc.ABC. It looks like:

from abc import ABC

class MyClass(ABC):
    def method(self):
        print("xxx")
    def wrapper(self):
        self.method()

mc = MyClass()
mc.method()

Why does the abc.ABC make the result wrong?

@fubuki8087 fubuki8087 added the question Further information is requested label Feb 10, 2025
@jketema
Copy link
Contributor

jketema commented Feb 10, 2025

Hi @fubuki8087

I've asked the CodeQL Python team to take a look.

@yoff
Copy link
Contributor

yoff commented Feb 11, 2025

Hi @fubuki8087, the PythonFunctionValue API is not really maintained anymore (it uses an old implementation of the call graph which was discarded precisely because of instabilities like the one you see). Unfortunately, we have not gotten around to expose the new call graph nicely. Partly because direct access to call resolution is rarely needed. But in case you do really need it, this comment shows you how to dig out the new call resolution predicate.

@fubuki8087
Copy link
Author

@yoff Now I understand why wrapper and method were not resolved to function values. This is because the ABC class they inherit from is constructed using a metaclass.

Actually, I just simply want to find all the call sites of a specific method (e.g. MyClass.methodName). However, this method might not be resolved due to the class it belongs to inheriting (directly or indirectly) from the ABC class (or any other unresolvable class), ultimately causing the call sites to be unfindable.

The comment you provided does indeed solve this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

3 participants