Mon, 21 Sep 2015 19:20:07 +0200
Patched the radon files to support Python 3.5 'async def'.
RadonMetrics/radon/visitors.py | file | annotate | diff | comparison | revisions |
--- a/RadonMetrics/radon/visitors.py Sun Sep 20 13:49:37 2015 +0200 +++ b/RadonMetrics/radon/visitors.py Mon Sep 21 19:20:07 2015 +0200 @@ -2,6 +2,10 @@ analysis concerning Cyclomatic Complexity is done. There is also the class HalsteadVisitor, that counts Halstead metrics.''' +# +# patched to support Python 3.5 'async def'. +# + import ast import operator import collections @@ -207,10 +211,10 @@ self.complexity += len(node.values) - 1 # Ifs, with and assert statements count all as 1. # Note: Lambda functions are not counted anymore, see #68 - elif name in ('With', 'If', 'IfExp'): + elif name in ('With', 'If', 'IfExp', 'AsyncWith'): self.complexity += 1 # The For and While blocks count as 1 plus the `else` block. - elif name in ('For', 'While'): + elif name in ('For', 'While', 'AsyncFor'): self.complexity += bool(node.orelse) + 1 # List, set, dict comprehensions and generator exps count as 1 plus # the `if` statement. @@ -247,6 +251,8 @@ self.classname, closures, body_complexity) self.functions.append(func) + visit_AsyncFunctionDef = visit_FunctionDef + def visit_ClassDef(self, node): '''When visiting classes a new visitor is created to recursively analyze the class' body and methods. @@ -364,3 +370,5 @@ self.operands += visitor.operands self.operators_seen.update(visitor.operators_seen) self.operands_seen.update(visitor.operands_seen) + + visit_AsyncFunctionDef = visit_FunctionDef