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

changeset 14
5f206edea27e
equal deleted inserted replaced
13:22bc345844e7 14:5f206edea27e
1 <!DOCTYPE html>
2 <html><head>
3 <title>Plugin_Metrics_Radon.RadonMetrics.radon.visitors</title>
4 <meta charset="UTF-8">
5 <style>
6 body {
7 background: #EDECE6;
8 margin: 0em 1em 10em 1em;
9 color: black;
10 }
11
12 h1 { color: white; background: #85774A; }
13 h2 { color: white; background: #85774A; }
14 h3 { color: white; background: #9D936E; }
15 h4 { color: white; background: #9D936E; }
16
17 a { color: #BA6D36; }
18
19 </style>
20 </head>
21 <body><a NAME="top" ID="top"></a>
22 <h1>Plugin_Metrics_Radon.RadonMetrics.radon.visitors</h1>
23
24 <h3>Global Attributes</h3>
25 <table>
26 <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>
27 </table>
28 <h3>Classes</h3>
29 <table>
30 <tr>
31 <td><a href="#Class">Class</a></td>
32 <td>Object representing a class block.</td>
33 </tr><tr>
34 <td><a href="#CodeVisitor">CodeVisitor</a></td>
35 <td>Base class for every NodeVisitors in `radon.visitors`.</td>
36 </tr><tr>
37 <td><a href="#ComplexityVisitor">ComplexityVisitor</a></td>
38 <td>A visitor that keeps track of the cyclomatic complexity of the elements.</td>
39 </tr><tr>
40 <td><a href="#Function">Function</a></td>
41 <td>Object represeting a function block.</td>
42 </tr><tr>
43 <td><a href="#HalsteadVisitor">HalsteadVisitor</a></td>
44 <td>Visitor that keeps track of operators and operands, in order to compute Halstead metrics (see :func:`radon.metrics.h_visit`).</td>
45 </tr>
46 </table>
47 <h3>Functions</h3>
48 <table>
49 <tr>
50 <td><a href="#code2ast">code2ast</a></td>
51 <td>Convert a string object into an AST object.</td>
52 </tr>
53 </table>
54 <hr /><hr />
55 <a NAME="Class" ID="Class"></a>
56 <h2>Class</h2>
57 <p>
58 Object representing a class block.
59 </p>
60 <h3>Derived from</h3>
61 BaseClass
62 <h3>Class Attributes</h3>
63 <table>
64 <tr><td>letter</td></tr>
65 </table>
66 <h3>Class Methods</h3>
67 <table>
68 <tr><td>None</td></tr>
69 </table>
70 <h3>Methods</h3>
71 <table>
72 <tr>
73 <td><a href="#Class.__str__">__str__</a></td>
74 <td>String representation of a class block.</td>
75 </tr><tr>
76 <td><a href="#Class.complexity">complexity</a></td>
77 <td>The average complexity of the class.</td>
78 </tr><tr>
79 <td><a href="#Class.fullname">fullname</a></td>
80 <td>The full name of the class.</td>
81 </tr>
82 </table>
83 <h3>Static Methods</h3>
84 <table>
85 <tr><td>None</td></tr>
86 </table>
87 <a NAME="Class.__str__" ID="Class.__str__"></a>
88 <h4>Class.__str__</h4>
89 <b>__str__</b>(<i></i>)
90 <p>
91 String representation of a class block.
92 </p><a NAME="Class.complexity" ID="Class.complexity"></a>
93 <h4>Class.complexity</h4>
94 <b>complexity</b>(<i></i>)
95 <p>
96 The average complexity of the class. It corresponds to the average
97 complexity of its methods plus one.
98 </p><a NAME="Class.fullname" ID="Class.fullname"></a>
99 <h4>Class.fullname</h4>
100 <b>fullname</b>(<i></i>)
101 <p>
102 The full name of the class. It is just its name. This attribute
103 exists for consistency (see :data:`Function.fullname`).
104 </p>
105 <div align="right"><a href="#top">Up</a></div>
106 <hr /><hr />
107 <a NAME="CodeVisitor" ID="CodeVisitor"></a>
108 <h2>CodeVisitor</h2>
109 <p>
110 Base class for every NodeVisitors in `radon.visitors`. It implements a
111 couple utility class methods and a static method.
112 </p>
113 <h3>Derived from</h3>
114 ast.NodeVisitor
115 <h3>Class Attributes</h3>
116 <table>
117 <tr><td>None</td></tr>
118 </table>
119 <h3>Class Methods</h3>
120 <table>
121 <tr>
122 <td><a href="#CodeVisitor.from_ast">from_ast</a></td>
123 <td>Instantiate the class from an AST node.</td>
124 </tr><tr>
125 <td><a href="#CodeVisitor.from_code">from_code</a></td>
126 <td>Instanciate the class from source code (string object).</td>
127 </tr>
128 </table>
129 <h3>Methods</h3>
130 <table>
131 <tr><td>None</td></tr>
132 </table>
133 <h3>Static Methods</h3>
134 <table>
135 <tr>
136 <td><a href="#CodeVisitor.get_name">get_name</a></td>
137 <td>Shorthand for ``obj.__class__.__name__``.</td>
138 </tr>
139 </table>
140 <a NAME="CodeVisitor.from_ast" ID="CodeVisitor.from_ast"></a>
141 <h4>CodeVisitor.from_ast (class method)</h4>
142 <b>from_ast</b>(<i>ast_node, **kwargs</i>)
143 <p>
144 Instantiate the class from an AST node. The `**kwargs` are
145 directly passed to the `ast.NodeVisitor` constructor.
146 </p><a NAME="CodeVisitor.from_code" ID="CodeVisitor.from_code"></a>
147 <h4>CodeVisitor.from_code (class method)</h4>
148 <b>from_code</b>(<i>code, **kwargs</i>)
149 <p>
150 Instanciate the class from source code (string object). The
151 `**kwargs` are directly passed to the `ast.NodeVisitor` constructor.
152 </p><a NAME="CodeVisitor.get_name" ID="CodeVisitor.get_name"></a>
153 <h4>CodeVisitor.get_name (static)</h4>
154 <b>get_name</b>(<i></i>)
155 <p>
156 Shorthand for ``obj.__class__.__name__``.
157 </p>
158 <div align="right"><a href="#top">Up</a></div>
159 <hr /><hr />
160 <a NAME="ComplexityVisitor" ID="ComplexityVisitor"></a>
161 <h2>ComplexityVisitor</h2>
162 <p>
163 A visitor that keeps track of the cyclomatic complexity of
164 the elements.
165 </p><p>
166 :param to_method: If True, every function is treated as a method. In this
167 case the *classname* parameter is used as class name.
168 :param classname: Name of parent class.
169 :param off: If True, the starting value for the complexity is set to 1,
170 otherwise to 0.
171 </p>
172 <h3>Derived from</h3>
173 CodeVisitor
174 <h3>Class Attributes</h3>
175 <table>
176 <tr><td>None</td></tr>
177 </table>
178 <h3>Class Methods</h3>
179 <table>
180 <tr><td>None</td></tr>
181 </table>
182 <h3>Methods</h3>
183 <table>
184 <tr>
185 <td><a href="#ComplexityVisitor.__init__">ComplexityVisitor</a></td>
186 <td></td>
187 </tr><tr>
188 <td><a href="#ComplexityVisitor.blocks">blocks</a></td>
189 <td>All the blocks visited.</td>
190 </tr><tr>
191 <td><a href="#ComplexityVisitor.classes_complexity">classes_complexity</a></td>
192 <td>The total complexity from all classes (i.e.</td>
193 </tr><tr>
194 <td><a href="#ComplexityVisitor.functions_complexity">functions_complexity</a></td>
195 <td>The total complexity from all functions (i.e.</td>
196 </tr><tr>
197 <td><a href="#ComplexityVisitor.generic_visit">generic_visit</a></td>
198 <td>Main entry point for the visitor.</td>
199 </tr><tr>
200 <td><a href="#ComplexityVisitor.max_line">max_line</a></td>
201 <td>The maximum line number among the analyzed lines.</td>
202 </tr><tr>
203 <td><a href="#ComplexityVisitor.total_complexity">total_complexity</a></td>
204 <td>The total complexity.</td>
205 </tr><tr>
206 <td><a href="#ComplexityVisitor.visit_Assert">visit_Assert</a></td>
207 <td>When visiting `assert` statements, the complexity is increased only if the `no_assert` attribute is `False`.</td>
208 </tr><tr>
209 <td><a href="#ComplexityVisitor.visit_ClassDef">visit_ClassDef</a></td>
210 <td>When visiting classes a new visitor is created to recursively analyze the class' body and methods.</td>
211 </tr><tr>
212 <td><a href="#ComplexityVisitor.visit_FunctionDef">visit_FunctionDef</a></td>
213 <td>When visiting functions a new visitor is created to recursively analyze the function's body.</td>
214 </tr>
215 </table>
216 <h3>Static Methods</h3>
217 <table>
218 <tr><td>None</td></tr>
219 </table>
220 <a NAME="ComplexityVisitor.__init__" ID="ComplexityVisitor.__init__"></a>
221 <h4>ComplexityVisitor (Constructor)</h4>
222 <b>ComplexityVisitor</b>(<i>to_method=False, classname=None, off=True, no_assert=False</i>)
223 <a NAME="ComplexityVisitor.blocks" ID="ComplexityVisitor.blocks"></a>
224 <h4>ComplexityVisitor.blocks</h4>
225 <b>blocks</b>(<i></i>)
226 <p>
227 All the blocks visited. These include: all the functions, the
228 classes and their methods. The returned list is not sorted.
229 </p><a NAME="ComplexityVisitor.classes_complexity" ID="ComplexityVisitor.classes_complexity"></a>
230 <h4>ComplexityVisitor.classes_complexity</h4>
231 <b>classes_complexity</b>(<i></i>)
232 <p>
233 The total complexity from all classes (i.e. the total number of
234 decision points + 1).
235 </p><a NAME="ComplexityVisitor.functions_complexity" ID="ComplexityVisitor.functions_complexity"></a>
236 <h4>ComplexityVisitor.functions_complexity</h4>
237 <b>functions_complexity</b>(<i></i>)
238 <p>
239 The total complexity from all functions (i.e. the total number of
240 decision points + 1).
241 </p><p>
242 This is *not* the sum of all the complexity from the functions. Rather,
243 it's the complexity of the code *inside* all the functions.
244 </p><a NAME="ComplexityVisitor.generic_visit" ID="ComplexityVisitor.generic_visit"></a>
245 <h4>ComplexityVisitor.generic_visit</h4>
246 <b>generic_visit</b>(<i>node</i>)
247 <p>
248 Main entry point for the visitor.
249 </p><a NAME="ComplexityVisitor.max_line" ID="ComplexityVisitor.max_line"></a>
250 <h4>ComplexityVisitor.max_line</h4>
251 <b>max_line</b>(<i>value</i>)
252 <p>
253 The maximum line number among the analyzed lines.
254 </p><a NAME="ComplexityVisitor.total_complexity" ID="ComplexityVisitor.total_complexity"></a>
255 <h4>ComplexityVisitor.total_complexity</h4>
256 <b>total_complexity</b>(<i></i>)
257 <p>
258 The total complexity. Computed adding up the visitor complexity, the
259 functions complexity, and the classes complexity.
260 </p><a NAME="ComplexityVisitor.visit_Assert" ID="ComplexityVisitor.visit_Assert"></a>
261 <h4>ComplexityVisitor.visit_Assert</h4>
262 <b>visit_Assert</b>(<i>node</i>)
263 <p>
264 When visiting `assert` statements, the complexity is increased only
265 if the `no_assert` attribute is `False`.
266 </p><a NAME="ComplexityVisitor.visit_ClassDef" ID="ComplexityVisitor.visit_ClassDef"></a>
267 <h4>ComplexityVisitor.visit_ClassDef</h4>
268 <b>visit_ClassDef</b>(<i>node</i>)
269 <p>
270 When visiting classes a new visitor is created to recursively
271 analyze the class' body and methods.
272 </p><a NAME="ComplexityVisitor.visit_FunctionDef" ID="ComplexityVisitor.visit_FunctionDef"></a>
273 <h4>ComplexityVisitor.visit_FunctionDef</h4>
274 <b>visit_FunctionDef</b>(<i>node</i>)
275 <p>
276 When visiting functions a new visitor is created to recursively
277 analyze the function's body.
278 </p>
279 <div align="right"><a href="#top">Up</a></div>
280 <hr /><hr />
281 <a NAME="Function" ID="Function"></a>
282 <h2>Function</h2>
283 <p>
284 Object represeting a function block.
285 </p>
286 <h3>Derived from</h3>
287 BaseFunc
288 <h3>Class Attributes</h3>
289 <table>
290 <tr><td>None</td></tr>
291 </table>
292 <h3>Class Methods</h3>
293 <table>
294 <tr><td>None</td></tr>
295 </table>
296 <h3>Methods</h3>
297 <table>
298 <tr>
299 <td><a href="#Function.__str__">__str__</a></td>
300 <td>String representation of a function block.</td>
301 </tr><tr>
302 <td><a href="#Function.fullname">fullname</a></td>
303 <td>The full name of the function.</td>
304 </tr><tr>
305 <td><a href="#Function.letter">letter</a></td>
306 <td>The letter representing the function.</td>
307 </tr>
308 </table>
309 <h3>Static Methods</h3>
310 <table>
311 <tr><td>None</td></tr>
312 </table>
313 <a NAME="Function.__str__" ID="Function.__str__"></a>
314 <h4>Function.__str__</h4>
315 <b>__str__</b>(<i></i>)
316 <p>
317 String representation of a function block.
318 </p><a NAME="Function.fullname" ID="Function.fullname"></a>
319 <h4>Function.fullname</h4>
320 <b>fullname</b>(<i></i>)
321 <p>
322 The full name of the function. If it is a method, then the full name
323 is:
324 {class name}.{method name}
325 Otherwise it is just the function name.
326 </p><a NAME="Function.letter" ID="Function.letter"></a>
327 <h4>Function.letter</h4>
328 <b>letter</b>(<i></i>)
329 <p>
330 The letter representing the function. It is `M` if the function is
331 actually a method, `F` otherwise.
332 </p>
333 <div align="right"><a href="#top">Up</a></div>
334 <hr /><hr />
335 <a NAME="HalsteadVisitor" ID="HalsteadVisitor"></a>
336 <h2>HalsteadVisitor</h2>
337 <p>
338 Visitor that keeps track of operators and operands, in order to compute
339 Halstead metrics (see :func:`radon.metrics.h_visit`).
340 </p>
341 <h3>Derived from</h3>
342 CodeVisitor
343 <h3>Class Attributes</h3>
344 <table>
345 <tr><td>types</td></tr>
346 </table>
347 <h3>Class Methods</h3>
348 <table>
349 <tr><td>None</td></tr>
350 </table>
351 <h3>Methods</h3>
352 <table>
353 <tr>
354 <td><a href="#HalsteadVisitor.__init__">HalsteadVisitor</a></td>
355 <td>*context* is a string used to keep track the analysis' context.</td>
356 </tr><tr>
357 <td><a href="#HalsteadVisitor.aux">aux</a></td>
358 <td>Actual function that updates the stats.</td>
359 </tr><tr>
360 <td><a href="#HalsteadVisitor.dispatch">dispatch</a></td>
361 <td>This decorator does all the hard work needed for every node.</td>
362 </tr><tr>
363 <td><a href="#HalsteadVisitor.distinct_operands">distinct_operands</a></td>
364 <td>The number of distinct operands.</td>
365 </tr><tr>
366 <td><a href="#HalsteadVisitor.distinct_operators">distinct_operators</a></td>
367 <td>The number of distinct operators.</td>
368 </tr><tr>
369 <td><a href="#HalsteadVisitor.visit_AugAssign">visit_AugAssign</a></td>
370 <td>An augmented assign (contains an operator).</td>
371 </tr><tr>
372 <td><a href="#HalsteadVisitor.visit_BinOp">visit_BinOp</a></td>
373 <td>A binary operator.</td>
374 </tr><tr>
375 <td><a href="#HalsteadVisitor.visit_BoolOp">visit_BoolOp</a></td>
376 <td>A boolean operator.</td>
377 </tr><tr>
378 <td><a href="#HalsteadVisitor.visit_Compare">visit_Compare</a></td>
379 <td>A comparison.</td>
380 </tr><tr>
381 <td><a href="#HalsteadVisitor.visit_FunctionDef">visit_FunctionDef</a></td>
382 <td>When visiting functions, another visitor is created to recursively analyze the function's body.</td>
383 </tr><tr>
384 <td><a href="#HalsteadVisitor.visit_UnaryOp">visit_UnaryOp</a></td>
385 <td>A unary operator.</td>
386 </tr>
387 </table>
388 <h3>Static Methods</h3>
389 <table>
390 <tr><td>None</td></tr>
391 </table>
392 <a NAME="HalsteadVisitor.__init__" ID="HalsteadVisitor.__init__"></a>
393 <h4>HalsteadVisitor (Constructor)</h4>
394 <b>HalsteadVisitor</b>(<i>context=None</i>)
395 <p>
396 *context* is a string used to keep track the analysis' context.
397 </p><a NAME="HalsteadVisitor.aux" ID="HalsteadVisitor.aux"></a>
398 <h4>HalsteadVisitor.aux</h4>
399 <b>aux</b>(<i>node</i>)
400 <p>
401 Actual function that updates the stats.
402 </p><a NAME="HalsteadVisitor.dispatch" ID="HalsteadVisitor.dispatch"></a>
403 <h4>HalsteadVisitor.dispatch</h4>
404 <b>dispatch</b>(<i></i>)
405 <p>
406 This decorator does all the hard work needed for every node.
407 </p><p>
408 The decorated method must return a tuple of 4 elements:
409 </p><p>
410 * the number of operators
411 * the number of operands
412 * the operators seen (a sequence)
413 * the operands seen (a sequence)
414 </p><a NAME="HalsteadVisitor.distinct_operands" ID="HalsteadVisitor.distinct_operands"></a>
415 <h4>HalsteadVisitor.distinct_operands</h4>
416 <b>distinct_operands</b>(<i></i>)
417 <p>
418 The number of distinct operands.
419 </p><a NAME="HalsteadVisitor.distinct_operators" ID="HalsteadVisitor.distinct_operators"></a>
420 <h4>HalsteadVisitor.distinct_operators</h4>
421 <b>distinct_operators</b>(<i></i>)
422 <p>
423 The number of distinct operators.
424 </p><a NAME="HalsteadVisitor.visit_AugAssign" ID="HalsteadVisitor.visit_AugAssign"></a>
425 <h4>HalsteadVisitor.visit_AugAssign</h4>
426 <b>visit_AugAssign</b>(<i>node</i>)
427 <p>
428 An augmented assign (contains an operator).
429 </p><a NAME="HalsteadVisitor.visit_BinOp" ID="HalsteadVisitor.visit_BinOp"></a>
430 <h4>HalsteadVisitor.visit_BinOp</h4>
431 <b>visit_BinOp</b>(<i>node</i>)
432 <p>
433 A binary operator.
434 </p><a NAME="HalsteadVisitor.visit_BoolOp" ID="HalsteadVisitor.visit_BoolOp"></a>
435 <h4>HalsteadVisitor.visit_BoolOp</h4>
436 <b>visit_BoolOp</b>(<i>node</i>)
437 <p>
438 A boolean operator.
439 </p><a NAME="HalsteadVisitor.visit_Compare" ID="HalsteadVisitor.visit_Compare"></a>
440 <h4>HalsteadVisitor.visit_Compare</h4>
441 <b>visit_Compare</b>(<i>node</i>)
442 <p>
443 A comparison.
444 </p><a NAME="HalsteadVisitor.visit_FunctionDef" ID="HalsteadVisitor.visit_FunctionDef"></a>
445 <h4>HalsteadVisitor.visit_FunctionDef</h4>
446 <b>visit_FunctionDef</b>(<i>node</i>)
447 <p>
448 When visiting functions, another visitor is created to recursively
449 analyze the function's body.
450 </p><a NAME="HalsteadVisitor.visit_UnaryOp" ID="HalsteadVisitor.visit_UnaryOp"></a>
451 <h4>HalsteadVisitor.visit_UnaryOp</h4>
452 <b>visit_UnaryOp</b>(<i>node</i>)
453 <p>
454 A unary operator.
455 </p>
456 <div align="right"><a href="#top">Up</a></div>
457 <hr /><hr />
458 <a NAME="code2ast" ID="code2ast"></a>
459 <h2>code2ast</h2>
460 <b>code2ast</b>(<i>source</i>)
461 <p>
462 Convert a string object into an AST object. This function attempts to
463 convert the string into bytes.
464 </p>
465 <div align="right"><a href="#top">Up</a></div>
466 <hr />
467 </body></html>

eric ide

mercurial