jendrikseipp / vulture

Find dead Python code
MIT License
3.38k stars 148 forks source link

False negatives when function/method/attribute name is in one of the whitelists/*_whitelist.py files. #307

Closed traverso-inspectifai closed 1 year ago

traverso-inspectifai commented 1 year ago

Hi,

I was building my own whitelist and I realized that vulture is just paying attention to the last name of each element in the whitelist. For example, if in your whitelist you have argparse.ArgumentParser().epilog, then every epilog attribute is whitelisted, even if it is inside of another class like this:

import argparse
class Dummy:
    epilog = 0
    dummy_argument = 0

    def forward(self):
        pass

The output of vulture is as follows:

sagemaker_source\report\pytorch_vis_wrap\pytorch_cam.py:13: unused class 'Dummy' (60% confidence)
sagemaker_source\report\pytorch_vis_wrap\pytorch_cam.py:15: unused variable 'dummy_argument' (60% confidence)

Thus, vulture is able to detect that neither de Dummy class nor the dummy_argument are used. However, it does not show any warning regarding epilog. This is because I imported argparse and therefore the argparse_whitelist.py file was automatically imported by vulture.

My expectation would be that vulture can differentiate between the two different epilog attributes. Whitelisting argparse.ArgumentParser().epilog shouldn't whitelist also Dummy().epilog.

Is my expectation wrong or is it a bug in the current implementation of vulture?

jendrikseipp commented 1 year ago

This is just due to a fundamental limitation of Vulture: it only looks at names and ignores scope completely. Such an approach is simpler to implement, but obviously leads to more false positives and false negatives.