eric6/Plugins/CheckerPlugins/CodeStyleChecker/AnnotationsChecker.py

changeset 7622
384e2aa5c073
parent 7610
df7025fe26a3
child 7637
c878e8255972
equal deleted inserted replaced
7621:ffd1f00ca376 7622:384e2aa5c073
7 Module implementing a checker for function type annotations. 7 Module implementing a checker for function type annotations.
8 """ 8 """
9 9
10 import sys 10 import sys
11 import ast 11 import ast
12
13 import AstUtilities
12 14
13 15
14 class AnnotationsChecker(object): 16 class AnnotationsChecker(object):
15 """ 17 """
16 Class implementing a checker for function type annotations. 18 Class implementing a checker for function type annotations.
459 complexity for 461 complexity for
460 @type ast.AST 462 @type ast.AST
461 @return annotation complexity 463 @return annotation complexity
462 @rtype = int 464 @rtype = int
463 """ 465 """
464 if isinstance(annotationNode, ast.Str): 466 if AstUtilities.isString(annotationNode):
465 annotationNode = ast.parse(annotationNode.s).body[0].value 467 annotationNode = ast.parse(annotationNode.s).body[0].value
466 if isinstance(annotationNode, ast.Subscript): 468 if isinstance(annotationNode, ast.Subscript):
467 return 1 + getAnnotationComplexity(annotationNode.slice.value) 469 return 1 + getAnnotationComplexity(annotationNode.slice.value)
468 if isinstance(annotationNode, ast.Tuple): 470 if isinstance(annotationNode, ast.Tuple):
469 return max(getAnnotationComplexity(n) for n in annotationNode.elts) 471 return max(getAnnotationComplexity(n) for n in annotationNode.elts)

eric ide

mercurial