vulture icon indicating copy to clipboard operation
vulture copied to clipboard

Skip functions decorated with abc.abstractmethod

Open xmnlab opened this issue 1 year ago • 6 comments

hey everyone!

I am new to vulture, and maybe there is a nice way to do that already, but something that I saw that maybe could be done automatically is to skip methods that is decorated by abc.abstractmethod.

for now I am just using noqa to skip that, Although I saw that is preferred to use whitelist .. but at least for now, I think that noqa would be simpler than adding a new file to the repo.

thank you so much!

xmnlab avatar Aug 07 '23 17:08 xmnlab

You can use --ignore-decorators @abc.abstractmethod for this purpose.

jendrikseipp avatar Aug 20 '23 13:08 jendrikseipp

thanks for your response @jendrikseipp !

for some reason it is not working:

$ vulture --min-confidence 80 --ignore-decorators @abc.abstractmethod src/arxir/builders/base.py 
src/arxir/builders/base.py:59: unused variable 'output_file' (100% confidence)
 58     @abc.abstractmethod
 59     def build(self, expr: ast.AST, output_file: str) -> None:
 60         ...
 61 

I am using the latest version:

$ vulture --version
vulture 2.9.1

any thoughts?

xmnlab avatar Aug 22 '23 02:08 xmnlab

Currently, --ignore-decorators @abc.abstractmethod ignores the build method, but not it's arguments. If you make a case for ignoring the arguments as well, we could think about how to implement this.

jendrikseipp avatar Aug 22 '23 09:08 jendrikseipp

not sure if I understood i correctly, but my case is very simple, abc.abstractmethod defines a method that will be overridden, that means that that function doesn't need to have any code inside, so any argument don't need to be used inside the function. In my example above, it just uses ... to define an empty body.

so, in this case, the vulture will alert that that variable (argument) is not used with 100% of confidence.

it would be nice to have some way to skip any argument of functions decorated by abc.abstractmethod .. or at least a generic way to do that where I can configure to skip any functions and their arguments decorated by a specific decorator (but not the functions that override the original ones).

xmnlab avatar Aug 22 '23 13:08 xmnlab

I don't know enough about the abc module, but from a quick glance at its docs, it seems that ignoring all arguments of all methods that have only ... (ellipsis) in their body should solve your problem, right? And if the method itself is not used anywhere, this should still be reported as dead code, right?

jendrikseipp avatar Aug 23 '23 09:08 jendrikseipp