On 04/23/2014 09:44 AM, Skip Montanaro wrote:
[...]
So, if I have this block of "constants":
ONE_SECOND = 1000 # ms
ONE_MINUTE = 60 * ONE_SECOND
it would be nice if I was told if any were unused.
[...] it might be nice to mark the
class as public then explicitly mark any private attributes:
[...]
Do any existing static analysis tools support anything like this?
pyflakes does exactly this first thing: tells you if any names are
unused. It does this the same way whether you are writing a module or a
stand-alone program. It requires modules which wish to expose constants
and such to declare them explicitly in __all__.
It does not have any mechanism for "private" versus "public" class or
instance attributes, because it is difficult to tell if they are used or
not by anything short of running the program. Reflect:
__metaclass__ = OhNoes
class Foo:
bar = 1
def __init__(self):
self.baz = 2
def frob(self):
if moon_phase() > 0.5:
self = 15
print self.baz
Rather than make guesses that are right 90% of the time and yield 10%
false positives, pyflakes takes the PEP 20 approach:
"""
In the face of ambiguity, refuse the temptation to guess.
"""
It is the opinion of pyflakes that determining the correctness of your
program in such complex situations is better served by unit tests.
_______________________________________________
code-quality mailing list
code-quality@python.org
https://mail.python.org/mailman/listinfo/code-quality