Skip to content
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

Skip functions decorated with abc.abstractmethod #317

Open
xmnlab opened this issue Aug 7, 2023 · 6 comments
Open

Skip functions decorated with abc.abstractmethod #317

xmnlab opened this issue Aug 7, 2023 · 6 comments

Comments

@xmnlab
Copy link

xmnlab commented Aug 7, 2023

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!

@jendrikseipp
Copy link
Owner

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

@xmnlab
Copy link
Author

xmnlab commented Aug 22, 2023

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?

@jendrikseipp
Copy link
Owner

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.

@xmnlab
Copy link
Author

xmnlab commented Aug 22, 2023

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).

@jendrikseipp
Copy link
Owner

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 jendrikseipp reopened this Aug 23, 2023
@dpinol
Copy link

dpinol commented Sep 25, 2024

I understand that --ignore-decorators @abc.abstractmethod is not a valid wowkaround here because what we need is a way to skip errors in interface method declarations, not in implementations of ABC's methods. Eg.

class Logger(ABC):
    @abstractmethod
    def log(self, message: str, arg1: int) -> None:
        raise NotImplementedError()

It should not complain about unused arg1 usage because this is not an implementation of a function, just an interface definition to be overridden by derived classes.

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

No branches or pull requests

3 participants