Skip to content
Snippets Groups Projects
Commit 98036c69 authored by Ian Cordasco's avatar Ian Cordasco
Browse files

Merge pull request #38 from PyCQA/bug/36

Add support for PEP 0492 keywords
parents c9bb16e5 4155ad6a
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -133,6 +133,8 @@ class PathGraphingAstVisitor(ASTVisitor):
self.graphs["%s%s" % (self.classname, node.name)] = self.graph
self.reset()
 
visitAsyncFunctionDef = visitFunctionDef
def visitClassDef(self, node):
old_classname = self.classname
self.classname += node.name + "."
Loading
Loading
@@ -158,13 +160,13 @@ class PathGraphingAstVisitor(ASTVisitor):
visitAssert = visitAssign = visitAugAssign = visitDelete = visitPrint = \
visitRaise = visitYield = visitImport = visitCall = visitSubscript = \
visitPass = visitContinue = visitBreak = visitGlobal = visitReturn = \
visitSimpleStatement
visitAwait = visitSimpleStatement
 
def visitLoop(self, node):
name = "Loop %d" % node.lineno
self._subgraph(node, name)
 
visitFor = visitWhile = visitLoop
visitAsyncFor = visitFor = visitWhile = visitLoop
 
def visitIf(self, node):
name = "If %d" % node.lineno
Loading
Loading
@@ -216,6 +218,8 @@ class PathGraphingAstVisitor(ASTVisitor):
self.appendPathNode(name)
self.dispatch_list(node.body)
 
visitAsyncWith = visitWith
 
class McCabeChecker(object):
"""McCabe cyclomatic complexity checker."""
Loading
Loading
[wheel]
universal = 1
[aliases]
test = pytest
Loading
Loading
@@ -33,7 +33,8 @@ setup(
license='Expat license',
py_modules=['mccabe'],
zip_safe=False,
test_suite='test_mccabe',
setup_requires=['pytest-runner'],
tests_require=['pytest'],
entry_points={
'flake8.extension': [
'C90 = mccabe:McCabeChecker',
Loading
Loading
Loading
Loading
@@ -5,6 +5,8 @@ try:
except ImportError:
from io import StringIO
 
import pytest
import mccabe
from mccabe import get_code_complexity
 
Loading
Loading
@@ -84,6 +86,19 @@ else:
print(4)
"""
 
async_keywords = """\
async def foobar(a, b, c):
await whatever(a, b, c)
if await b:
pass
async with c:
pass
async for x in a:
pass
"""
 
def get_complexity_number(snippet, strio, max=0):
"""Get the complexity number from the printed string."""
Loading
Loading
@@ -164,6 +179,13 @@ class McCabeTestCase(unittest.TestCase):
def test_try_else(self):
self.assert_complexity(try_else, 4)
 
@pytest.mark.skipif(sys.version_info < (3, 5),
reason="Async keywords are only valid on Python 3.5+")
def test_async_keywords(self):
"""Validate that we properly process async keyword usage."""
complexity = get_complexity_number(async_keywords, self.strio)
self.assertEqual(complexity, 3)
 
class RegressionTests(unittest.TestCase):
def setUp(self):
Loading
Loading
[tox]
envlist =
py26,py27,py33,py34,flake8
py26,py27,py33,py34,py35,flake8
 
[testenv]
deps =
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