def _find_unused_code(filenames): """ :param filenames: List of filenames to check. :return: Generator of Result objects. """ vulture = Vulture() vulture.scavenge(filenames) for item in vulture.get_unused_code(): yield Result.from_values(origin='VultureBear', message=item.message, file=item.filename, line=item.first_lineno, end_line=item.last_lineno, confidence=item.confidence)
def _find_unused_code(filenames): """ :param filenames: List of filenames to check. :return: Generator of Result objects. """ def file_lineno(item): return (item.filename.lower(), item.lineno) vulture = Vulture() vulture.scavenge(filenames) for item in sorted(vulture.unused_funcs + vulture.unused_imports + vulture.unused_props + vulture.unused_vars + vulture.unused_attrs, key=file_lineno): message = 'Unused {0}: {1}'.format(item.typ, item) yield Result.from_values(origin='VultureBear', message=message, file=item.filename, line=item.lineno)
def _find_unused_code(filenames): """ :param filenames: List of filenames to check. :return: Generator of Result objects. """ def file_lineno(item): return (item.filename.lower(), item.lineno) vulture = Vulture() vulture.scavenge(filenames) for item in sorted( vulture.unused_funcs + vulture.unused_imports + vulture.unused_props + vulture.unused_vars + vulture.unused_attrs, key=file_lineno): message = 'Unused {0}: {1}'.format(item.typ, item) yield Result.from_values(origin='VultureBear', message=message, file=item.filename, line=item.lineno, confidence=CONFIDENCE_MAP[item.typ])
def v(): return Vulture(verbose=True)
def __init__(self, found_files): Vulture.__init__(self, exclude=None, verbose=False) self._files = found_files
def __init__(self, found_files): Vulture.__init__(self, verbose=False) self._files = found_files self._internal_messages = [] self.file = None self.filename = None
def __init__(self, found_files): Vulture.__init__(self, exclude=None, verbose=False) self._files = found_files self._internal_messages = []
from vulture import Vulture vulture = Vulture() files = ['file1.py', 'file2.py'] vulture.scavenge(files) for item in vulture.get_unused_code(): # filter items print(item)
"""Look for unreachable code.""" import argparse import sys from vulture import Vulture if __name__ == "__main__": parser = argparse.ArgumentParser() parser.add_argument("files", nargs="*") args = parser.parse_args() v = Vulture() v.scavenge(args.files) ret = 0 for item in v.get_unused_code(min_confidence=100): if item.typ == "unreachable_code": print(item.get_report()) ret = 1 sys.exit(ret)