Is there a lint tool that can spot unused classes/methods/attributes/functions/etc?

Mark Summerfield list at qtrac.plus.com
Thu Feb 2 04:05:45 EST 2017


Suppose I have a project with an application .py file and various module .py files all in the same directory, and after lots of refactoring and other changes the modules contain lots of unused stuff. Is there a lint tool that will spot the unused things so that I can get rid of them?

I've tried flake and pylint but neither seem to help.

Here's the smallest example I can think of:

# app.py
import Mod
a = Mod.A()
print(a.quack())

# Mod.py
class A: # Used in app.py
    def __init__(self):
        self.x = "hello" # Used in quack() which is used in app.py
        self.y = 7 # Unused
    @property
    def z(self): # Unused
        return 4.5
    def quack(self): # Used in app.py
        return self.x
class B: # Unused
    pass
CONST = 999 # Unused
def func(): # Unused
    pass

Thanks.



More information about the Python-list mailing list