mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-14 00:14:46 +00:00
add warning code W901 to mccabe
This commit is contained in:
parent
753ef01fb9
commit
a2ac0c3035
1 changed files with 14 additions and 5 deletions
|
|
@ -13,6 +13,8 @@ import optparse
|
||||||
import sys
|
import sys
|
||||||
from collections import defaultdict
|
from collections import defaultdict
|
||||||
|
|
||||||
|
WARNING_CODE = "W901"
|
||||||
|
|
||||||
|
|
||||||
class ASTVisitor:
|
class ASTVisitor:
|
||||||
|
|
||||||
|
|
@ -63,8 +65,10 @@ class PathNode:
|
||||||
|
|
||||||
|
|
||||||
class PathGraph:
|
class PathGraph:
|
||||||
def __init__(self, name):
|
def __init__(self, name, entity, lineno):
|
||||||
self.name = name
|
self.name = name
|
||||||
|
self.entity = entity
|
||||||
|
self.lineno = lineno
|
||||||
self.nodes = defaultdict(list)
|
self.nodes = defaultdict(list)
|
||||||
|
|
||||||
def connect(self, n1, n2):
|
def connect(self, n1, n2):
|
||||||
|
|
@ -122,7 +126,7 @@ class PathGraphingAstVisitor(ASTVisitor):
|
||||||
self.graph.connect(pathnode, bottom)
|
self.graph.connect(pathnode, bottom)
|
||||||
self.tail = bottom
|
self.tail = bottom
|
||||||
else:
|
else:
|
||||||
self.graph = PathGraph(name)
|
self.graph = PathGraph(name, entity, node.lineno)
|
||||||
pathnode = PathNode(name)
|
pathnode = PathNode(name)
|
||||||
self.tail = pathnode
|
self.tail = pathnode
|
||||||
self.default(node)
|
self.default(node)
|
||||||
|
|
@ -163,7 +167,7 @@ class PathGraphingAstVisitor(ASTVisitor):
|
||||||
|
|
||||||
if self.graph is None:
|
if self.graph is None:
|
||||||
# global loop
|
# global loop
|
||||||
self.graph = PathGraph(name)
|
self.graph = PathGraph(name, name, node.lineno)
|
||||||
pathnode = PathNode(name)
|
pathnode = PathNode(name)
|
||||||
self.tail = pathnode
|
self.tail = pathnode
|
||||||
self.default(node)
|
self.default(node)
|
||||||
|
|
@ -239,8 +243,13 @@ def get_code_complexity(code, min=7, filename='stdin'):
|
||||||
# ?
|
# ?
|
||||||
continue
|
continue
|
||||||
if graph.complexity() >= min:
|
if graph.complexity() >= min:
|
||||||
msg = '%s:%s is too complex (%d)' % (filename,
|
msg = '%s:%d:1 %s %r is too complex (%d)' % (
|
||||||
graph.name, graph.complexity())
|
filename,
|
||||||
|
graph.lineno,
|
||||||
|
WARNING_CODE,
|
||||||
|
graph.entity,
|
||||||
|
graph.complexity(),
|
||||||
|
)
|
||||||
complex.append(msg)
|
complex.append(msg)
|
||||||
|
|
||||||
if len(complex) == 0:
|
if len(complex) == 0:
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue