/usr/share/pyshared/pychecker2/ConditionalChecks.py is in pychecker 0.8.19-11.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 | from pychecker2.Check import Check
from pychecker2.util import BaseVisitor
from compiler import ast, walk
class ConstantFinder(BaseVisitor):
def __init__(self):
self.result = []
def visitConst(self, node):
if isinstance(node.parent, (ast.Or, ast.Not, ast.And)):
self.result.append((node, `node.value`))
def visitName(self, node):
if node.name == 'None':
if isinstance(node.parent, (ast.Or, ast.Not, ast.And)):
self.result.append((node, 'None'))
class GetConditionalConstants(BaseVisitor):
def __init__(self):
self.result = []
def visitIf(self, node):
for test, code in node.tests:
self.result.extend(walk(test, ConstantFinder()).result)
def visitWhile(self, node):
self.result.extend(walk(node.test, ConstantFinder()).result)
visitListCompIf = visitWhile
visitAssert = visitWhile
class ConstantCheck(Check):
constantInConditional = \
Warning('Report constants used in conditionals',
'Constant used in conditional %s')
def check(self, file, unused_checker):
if file.parseTree:
v = GetConditionalConstants()
for n, value in walk(file.parseTree, v).result:
file.warning(n, self.constantInConditional, value)
|