jendrikseipp/vulture

ignore click functions

davetapley opened this issue · 3 comments

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.

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

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? 😁

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