Is there a lint tool that can spot unused classes/methods/attributes/functions/etc?
Peter Otten
__peter__ at web.de
Thu Feb 2 05:03:33 EST 2017
Mark Summerfield wrote:
> 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.
I often "find" unused code with coverage.py. However, it cannot detect
statements that are executed but have no effect, and thus will report only
A.z() and func() in the example below.
> 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