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

ignore click functions #329

Open
davetapley opened this issue Sep 30, 2023 · 3 comments
Open

ignore click functions #329

davetapley opened this issue Sep 30, 2023 · 3 comments

Comments

@davetapley
Copy link

Would a feature be welcome to detect and ignore click methods?

I already have them all grouped in a cli/ sub-dir which I can --exclude,
but it would be nice if Vulture could figure it out 😁


I think it'll require more than just adding to whitelists/ since the names are arbitrary, but...

Since click uses a decorator which makes the functions an instance of click.Command, I think it could be as easy as:

@cli.command()
def sync():
    click.echo('Syncing')

def unused():
   print('I am unused)

from click import Command

isinstance(sync, Command)
# True

isinstance(unused, Command)   
# False

... and in a find_spec check to see if the click is available.

@jendrikseipp
Copy link
Owner

Have you tried ignoring these functions with --ignore-decorators "@cli.command"?

@davetapley
Copy link
Author

I must confess I haven't tried it, but I assume --ignore-decorators won't work* because the name of the decorator (i.e., @cli) depends on the name of the function defining the @click.group(). e.g., from their docs:

import click

@click.group()
def cli1():
    pass

@cli1.command()
def cmd1():
    """Command on cli1"""

@click.group()
def cli2():
    pass

@cli2.command()
def cmd2():
    """Command on cli2"""

I suppose one could be sure to manually add an --ignore-decorators for each @click.group() in their codebase, but a bit onerous.


* unless there is some real deep magic going on in Vulture? 😁

@jendrikseipp
Copy link
Owner

You can use a wildcard * to catch all name variations. Can you try this and post the solution here?

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

2 participants