RadonMetrics/Documentation/source/Plugin_Metrics_Radon.RadonMetrics.radon.visitors.html

Sun, 20 Sep 2015 12:16:27 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Sun, 20 Sep 2015 12:16:27 +0200
changeset 15
62ffe3d426e5
parent 14
5f206edea27e
permissions
-rw-r--r--

Added a context menu to the result list of the cyclomatic complexity dialog.

<!DOCTYPE html>
<html><head>
<title>Plugin_Metrics_Radon.RadonMetrics.radon.visitors</title>
<meta charset="UTF-8">
<style>
body {
    background: #EDECE6;
    margin: 0em 1em 10em 1em;
    color: black;
}

h1 { color: white; background: #85774A; }
h2 { color: white; background: #85774A; }
h3 { color: white; background: #9D936E; }
h4 { color: white; background: #9D936E; }
    
a { color: #BA6D36; }

</style>
</head>
<body><a NAME="top" ID="top"></a>
<h1>Plugin_Metrics_Radon.RadonMetrics.radon.visitors</h1>

<h3>Global Attributes</h3>
<table>
<tr><td>BaseClass</td></tr><tr><td>BaseFunc</td></tr><tr><td>GET_COMPLEXITY</td></tr><tr><td>GET_ENDLINE</td></tr><tr><td>GET_REAL_COMPLEXITY</td></tr><tr><td>NAMES_GETTER</td></tr>
</table>
<h3>Classes</h3>
<table>
<tr>
<td><a href="#Class">Class</a></td>
<td>Object representing a class block.</td>
</tr><tr>
<td><a href="#CodeVisitor">CodeVisitor</a></td>
<td>Base class for every NodeVisitors in `radon.visitors`.</td>
</tr><tr>
<td><a href="#ComplexityVisitor">ComplexityVisitor</a></td>
<td>A visitor that keeps track of the cyclomatic complexity of the elements.</td>
</tr><tr>
<td><a href="#Function">Function</a></td>
<td>Object represeting a function block.</td>
</tr><tr>
<td><a href="#HalsteadVisitor">HalsteadVisitor</a></td>
<td>Visitor that keeps track of operators and operands, in order to compute Halstead metrics (see :func:`radon.metrics.h_visit`).</td>
</tr>
</table>
<h3>Functions</h3>
<table>
<tr>
<td><a href="#code2ast">code2ast</a></td>
<td>Convert a string object into an AST object.</td>
</tr>
</table>
<hr /><hr />
<a NAME="Class" ID="Class"></a>
<h2>Class</h2>
<p>
Object representing a class block.
</p>
<h3>Derived from</h3>
BaseClass
<h3>Class Attributes</h3>
<table>
<tr><td>letter</td></tr>
</table>
<h3>Class Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Methods</h3>
<table>
<tr>
<td><a href="#Class.__str__">__str__</a></td>
<td>String representation of a class block.</td>
</tr><tr>
<td><a href="#Class.complexity">complexity</a></td>
<td>The average complexity of the class.</td>
</tr><tr>
<td><a href="#Class.fullname">fullname</a></td>
<td>The full name of the class.</td>
</tr>
</table>
<h3>Static Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<a NAME="Class.__str__" ID="Class.__str__"></a>
<h4>Class.__str__</h4>
<b>__str__</b>(<i></i>)
<p>
String representation of a class block.
</p><a NAME="Class.complexity" ID="Class.complexity"></a>
<h4>Class.complexity</h4>
<b>complexity</b>(<i></i>)
<p>
The average complexity of the class. It corresponds to the average
        complexity of its methods plus one.
</p><a NAME="Class.fullname" ID="Class.fullname"></a>
<h4>Class.fullname</h4>
<b>fullname</b>(<i></i>)
<p>
The full name of the class. It is just its name. This attribute
        exists for consistency (see :data:`Function.fullname`).
</p>
<div align="right"><a href="#top">Up</a></div>
<hr /><hr />
<a NAME="CodeVisitor" ID="CodeVisitor"></a>
<h2>CodeVisitor</h2>
<p>
Base class for every NodeVisitors in `radon.visitors`. It implements a
    couple utility class methods and a static method.
</p>
<h3>Derived from</h3>
ast.NodeVisitor
<h3>Class Attributes</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Class Methods</h3>
<table>
<tr>
<td><a href="#CodeVisitor.from_ast">from_ast</a></td>
<td>Instantiate the class from an AST node.</td>
</tr><tr>
<td><a href="#CodeVisitor.from_code">from_code</a></td>
<td>Instanciate the class from source code (string object).</td>
</tr>
</table>
<h3>Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Static Methods</h3>
<table>
<tr>
<td><a href="#CodeVisitor.get_name">get_name</a></td>
<td>Shorthand for ``obj.__class__.__name__``.</td>
</tr>
</table>
<a NAME="CodeVisitor.from_ast" ID="CodeVisitor.from_ast"></a>
<h4>CodeVisitor.from_ast (class method)</h4>
<b>from_ast</b>(<i>ast_node, **kwargs</i>)
<p>
Instantiate the class from an AST node. The `**kwargs` are
        directly passed to the `ast.NodeVisitor` constructor.
</p><a NAME="CodeVisitor.from_code" ID="CodeVisitor.from_code"></a>
<h4>CodeVisitor.from_code (class method)</h4>
<b>from_code</b>(<i>code, **kwargs</i>)
<p>
Instanciate the class from source code (string object). The
        `**kwargs` are directly passed to the `ast.NodeVisitor` constructor.
</p><a NAME="CodeVisitor.get_name" ID="CodeVisitor.get_name"></a>
<h4>CodeVisitor.get_name (static)</h4>
<b>get_name</b>(<i></i>)
<p>
Shorthand for ``obj.__class__.__name__``.
</p>
<div align="right"><a href="#top">Up</a></div>
<hr /><hr />
<a NAME="ComplexityVisitor" ID="ComplexityVisitor"></a>
<h2>ComplexityVisitor</h2>
<p>
A visitor that keeps track of the cyclomatic complexity of
    the elements.
</p><p>
    :param to_method: If True, every function is treated as a method. In this
        case the *classname* parameter is used as class name.
    :param classname: Name of parent class.
    :param off: If True, the starting value for the complexity is set to 1,
        otherwise to 0.
</p>
<h3>Derived from</h3>
CodeVisitor
<h3>Class Attributes</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Class Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Methods</h3>
<table>
<tr>
<td><a href="#ComplexityVisitor.__init__">ComplexityVisitor</a></td>
<td></td>
</tr><tr>
<td><a href="#ComplexityVisitor.blocks">blocks</a></td>
<td>All the blocks visited.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.classes_complexity">classes_complexity</a></td>
<td>The total complexity from all classes (i.e.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.functions_complexity">functions_complexity</a></td>
<td>The total complexity from all functions (i.e.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.generic_visit">generic_visit</a></td>
<td>Main entry point for the visitor.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.max_line">max_line</a></td>
<td>The maximum line number among the analyzed lines.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.total_complexity">total_complexity</a></td>
<td>The total complexity.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.visit_Assert">visit_Assert</a></td>
<td>When visiting `assert` statements, the complexity is increased only if the `no_assert` attribute is `False`.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.visit_ClassDef">visit_ClassDef</a></td>
<td>When visiting classes a new visitor is created to recursively analyze the class' body and methods.</td>
</tr><tr>
<td><a href="#ComplexityVisitor.visit_FunctionDef">visit_FunctionDef</a></td>
<td>When visiting functions a new visitor is created to recursively analyze the function's body.</td>
</tr>
</table>
<h3>Static Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<a NAME="ComplexityVisitor.__init__" ID="ComplexityVisitor.__init__"></a>
<h4>ComplexityVisitor (Constructor)</h4>
<b>ComplexityVisitor</b>(<i>to_method=False, classname=None, off=True, no_assert=False</i>)
<a NAME="ComplexityVisitor.blocks" ID="ComplexityVisitor.blocks"></a>
<h4>ComplexityVisitor.blocks</h4>
<b>blocks</b>(<i></i>)
<p>
All the blocks visited. These include: all the functions, the
        classes and their methods. The returned list is not sorted.
</p><a NAME="ComplexityVisitor.classes_complexity" ID="ComplexityVisitor.classes_complexity"></a>
<h4>ComplexityVisitor.classes_complexity</h4>
<b>classes_complexity</b>(<i></i>)
<p>
The total complexity from all classes (i.e. the total number of
        decision points + 1).
</p><a NAME="ComplexityVisitor.functions_complexity" ID="ComplexityVisitor.functions_complexity"></a>
<h4>ComplexityVisitor.functions_complexity</h4>
<b>functions_complexity</b>(<i></i>)
<p>
The total complexity from all functions (i.e. the total number of
        decision points + 1).
</p><p>
        This is *not* the sum of all the complexity from the functions. Rather,
        it's the complexity of the code *inside* all the functions.
</p><a NAME="ComplexityVisitor.generic_visit" ID="ComplexityVisitor.generic_visit"></a>
<h4>ComplexityVisitor.generic_visit</h4>
<b>generic_visit</b>(<i>node</i>)
<p>
Main entry point for the visitor.
</p><a NAME="ComplexityVisitor.max_line" ID="ComplexityVisitor.max_line"></a>
<h4>ComplexityVisitor.max_line</h4>
<b>max_line</b>(<i>value</i>)
<p>
The maximum line number among the analyzed lines.
</p><a NAME="ComplexityVisitor.total_complexity" ID="ComplexityVisitor.total_complexity"></a>
<h4>ComplexityVisitor.total_complexity</h4>
<b>total_complexity</b>(<i></i>)
<p>
The total complexity. Computed adding up the visitor complexity, the
        functions complexity, and the classes complexity.
</p><a NAME="ComplexityVisitor.visit_Assert" ID="ComplexityVisitor.visit_Assert"></a>
<h4>ComplexityVisitor.visit_Assert</h4>
<b>visit_Assert</b>(<i>node</i>)
<p>
When visiting `assert` statements, the complexity is increased only
        if the `no_assert` attribute is `False`.
</p><a NAME="ComplexityVisitor.visit_ClassDef" ID="ComplexityVisitor.visit_ClassDef"></a>
<h4>ComplexityVisitor.visit_ClassDef</h4>
<b>visit_ClassDef</b>(<i>node</i>)
<p>
When visiting classes a new visitor is created to recursively
        analyze the class' body and methods.
</p><a NAME="ComplexityVisitor.visit_FunctionDef" ID="ComplexityVisitor.visit_FunctionDef"></a>
<h4>ComplexityVisitor.visit_FunctionDef</h4>
<b>visit_FunctionDef</b>(<i>node</i>)
<p>
When visiting functions a new visitor is created to recursively
        analyze the function's body.
</p>
<div align="right"><a href="#top">Up</a></div>
<hr /><hr />
<a NAME="Function" ID="Function"></a>
<h2>Function</h2>
<p>
Object represeting a function block.
</p>
<h3>Derived from</h3>
BaseFunc
<h3>Class Attributes</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Class Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Methods</h3>
<table>
<tr>
<td><a href="#Function.__str__">__str__</a></td>
<td>String representation of a function block.</td>
</tr><tr>
<td><a href="#Function.fullname">fullname</a></td>
<td>The full name of the function.</td>
</tr><tr>
<td><a href="#Function.letter">letter</a></td>
<td>The letter representing the function.</td>
</tr>
</table>
<h3>Static Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<a NAME="Function.__str__" ID="Function.__str__"></a>
<h4>Function.__str__</h4>
<b>__str__</b>(<i></i>)
<p>
String representation of a function block.
</p><a NAME="Function.fullname" ID="Function.fullname"></a>
<h4>Function.fullname</h4>
<b>fullname</b>(<i></i>)
<p>
The full name of the function. If it is a method, then the full name
        is:
                {class name}.{method name}
        Otherwise it is just the function name.
</p><a NAME="Function.letter" ID="Function.letter"></a>
<h4>Function.letter</h4>
<b>letter</b>(<i></i>)
<p>
The letter representing the function. It is `M` if the function is
        actually a method, `F` otherwise.
</p>
<div align="right"><a href="#top">Up</a></div>
<hr /><hr />
<a NAME="HalsteadVisitor" ID="HalsteadVisitor"></a>
<h2>HalsteadVisitor</h2>
<p>
Visitor that keeps track of operators and operands, in order to compute
    Halstead metrics (see :func:`radon.metrics.h_visit`).
</p>
<h3>Derived from</h3>
CodeVisitor
<h3>Class Attributes</h3>
<table>
<tr><td>types</td></tr>
</table>
<h3>Class Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<h3>Methods</h3>
<table>
<tr>
<td><a href="#HalsteadVisitor.__init__">HalsteadVisitor</a></td>
<td>*context* is a string used to keep track the analysis' context.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.aux">aux</a></td>
<td>Actual function that updates the stats.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.dispatch">dispatch</a></td>
<td>This decorator does all the hard work needed for every node.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.distinct_operands">distinct_operands</a></td>
<td>The number of distinct operands.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.distinct_operators">distinct_operators</a></td>
<td>The number of distinct operators.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.visit_AugAssign">visit_AugAssign</a></td>
<td>An augmented assign (contains an operator).</td>
</tr><tr>
<td><a href="#HalsteadVisitor.visit_BinOp">visit_BinOp</a></td>
<td>A binary operator.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.visit_BoolOp">visit_BoolOp</a></td>
<td>A boolean operator.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.visit_Compare">visit_Compare</a></td>
<td>A comparison.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.visit_FunctionDef">visit_FunctionDef</a></td>
<td>When visiting functions, another visitor is created to recursively analyze the function's body.</td>
</tr><tr>
<td><a href="#HalsteadVisitor.visit_UnaryOp">visit_UnaryOp</a></td>
<td>A unary operator.</td>
</tr>
</table>
<h3>Static Methods</h3>
<table>
<tr><td>None</td></tr>
</table>
<a NAME="HalsteadVisitor.__init__" ID="HalsteadVisitor.__init__"></a>
<h4>HalsteadVisitor (Constructor)</h4>
<b>HalsteadVisitor</b>(<i>context=None</i>)
<p>
*context* is a string used to keep track the analysis' context.
</p><a NAME="HalsteadVisitor.aux" ID="HalsteadVisitor.aux"></a>
<h4>HalsteadVisitor.aux</h4>
<b>aux</b>(<i>node</i>)
<p>
Actual function that updates the stats.
</p><a NAME="HalsteadVisitor.dispatch" ID="HalsteadVisitor.dispatch"></a>
<h4>HalsteadVisitor.dispatch</h4>
<b>dispatch</b>(<i></i>)
<p>
This decorator does all the hard work needed for every node.
</p><p>
        The decorated method must return a tuple of 4 elements:
</p><p>
            * the number of operators
            * the number of operands
            * the operators seen (a sequence)
            * the operands seen (a sequence)
</p><a NAME="HalsteadVisitor.distinct_operands" ID="HalsteadVisitor.distinct_operands"></a>
<h4>HalsteadVisitor.distinct_operands</h4>
<b>distinct_operands</b>(<i></i>)
<p>
The number of distinct operands.
</p><a NAME="HalsteadVisitor.distinct_operators" ID="HalsteadVisitor.distinct_operators"></a>
<h4>HalsteadVisitor.distinct_operators</h4>
<b>distinct_operators</b>(<i></i>)
<p>
The number of distinct operators.
</p><a NAME="HalsteadVisitor.visit_AugAssign" ID="HalsteadVisitor.visit_AugAssign"></a>
<h4>HalsteadVisitor.visit_AugAssign</h4>
<b>visit_AugAssign</b>(<i>node</i>)
<p>
An augmented assign (contains an operator).
</p><a NAME="HalsteadVisitor.visit_BinOp" ID="HalsteadVisitor.visit_BinOp"></a>
<h4>HalsteadVisitor.visit_BinOp</h4>
<b>visit_BinOp</b>(<i>node</i>)
<p>
A binary operator.
</p><a NAME="HalsteadVisitor.visit_BoolOp" ID="HalsteadVisitor.visit_BoolOp"></a>
<h4>HalsteadVisitor.visit_BoolOp</h4>
<b>visit_BoolOp</b>(<i>node</i>)
<p>
A boolean operator.
</p><a NAME="HalsteadVisitor.visit_Compare" ID="HalsteadVisitor.visit_Compare"></a>
<h4>HalsteadVisitor.visit_Compare</h4>
<b>visit_Compare</b>(<i>node</i>)
<p>
A comparison.
</p><a NAME="HalsteadVisitor.visit_FunctionDef" ID="HalsteadVisitor.visit_FunctionDef"></a>
<h4>HalsteadVisitor.visit_FunctionDef</h4>
<b>visit_FunctionDef</b>(<i>node</i>)
<p>
When visiting functions, another visitor is created to recursively
        analyze the function's body.
</p><a NAME="HalsteadVisitor.visit_UnaryOp" ID="HalsteadVisitor.visit_UnaryOp"></a>
<h4>HalsteadVisitor.visit_UnaryOp</h4>
<b>visit_UnaryOp</b>(<i>node</i>)
<p>
A unary operator.
</p>
<div align="right"><a href="#top">Up</a></div>
<hr /><hr />
<a NAME="code2ast" ID="code2ast"></a>
<h2>code2ast</h2>
<b>code2ast</b>(<i>source</i>)
<p>
Convert a string object into an AST object. This function attempts to
    convert the string into bytes.
</p>
<div align="right"><a href="#top">Up</a></div>
<hr />
</body></html>

eric ide

mercurial