Skip to content
Snippets Groups Projects
Commit 9253a9c2 authored by Anthony Sottile's avatar Anthony Sottile
Browse files

Have mccabe consider all statements as statements

parent 682145a3
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -160,10 +160,11 @@ class PathGraphingAstVisitor(ASTVisitor):
name = "Stmt %d" % lineno
self.appendPathNode(name)
 
visitAssert = visitAssign = visitAugAssign = visitDelete = visitPrint = \
visitRaise = visitYield = visitImport = visitCall = visitSubscript = \
visitPass = visitContinue = visitBreak = visitGlobal = visitReturn = \
visitAwait = visitSimpleStatement
def default(self, node):
if isinstance(node, ast.stmt):
self.visitSimpleStatement(node)
else:
super(PathGraphingAstVisitor, self).default(node)
 
def visitLoop(self, node):
name = "Loop %d" % node.lineno
Loading
Loading
Loading
Loading
@@ -16,6 +16,12 @@ from mccabe import get_code_complexity
trivial = 'def f(): pass'
 
 
expr_as_statement = '''\
def f():
"""docstring"""
'''
sequential = """\
def f(n):
k = n + 4
Loading
Loading
@@ -176,6 +182,10 @@ class McCabeTestCase(unittest.TestCase):
printed_message = self.strio.getvalue()
self.assertEqual(printed_message, "")
 
def test_expr_as_statement(self):
complexity = get_complexity_number(expr_as_statement, self.strio)
self.assertEqual(complexity, 1)
def test_try_else(self):
self.assert_complexity(try_else, 4)
 
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment