|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.MiscellaneousChecker</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> |
|
22 <a NAME="top" ID="top"></a> |
|
23 <h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Miscellaneous.MiscellaneousChecker</h1> |
|
24 |
|
25 <p> |
|
26 Module implementing a checker for miscellaneous checks. |
|
27 </p> |
|
28 <h3>Global Attributes</h3> |
|
29 |
|
30 <table> |
|
31 <tr><td>None</td></tr> |
|
32 </table> |
|
33 <h3>Classes</h3> |
|
34 |
|
35 <table> |
|
36 |
|
37 <tr> |
|
38 <td><a href="#BugBearVisitor">BugBearVisitor</a></td> |
|
39 <td>Class implementing a node visitor to check for various topics.</td> |
|
40 </tr> |
|
41 <tr> |
|
42 <td><a href="#DateTimeVisitor">DateTimeVisitor</a></td> |
|
43 <td>Class implementing a node visitor to check datetime function calls.</td> |
|
44 </tr> |
|
45 <tr> |
|
46 <td><a href="#LoggingVisitor">LoggingVisitor</a></td> |
|
47 <td>Class implementing a node visitor to check logging statements.</td> |
|
48 </tr> |
|
49 <tr> |
|
50 <td><a href="#MiscellaneousChecker">MiscellaneousChecker</a></td> |
|
51 <td>Class implementing a checker for miscellaneous checks.</td> |
|
52 </tr> |
|
53 <tr> |
|
54 <td><a href="#NameFinder">NameFinder</a></td> |
|
55 <td>Class to extract a name out of a tree of nodes.</td> |
|
56 </tr> |
|
57 <tr> |
|
58 <td><a href="#ReturnVisitor">ReturnVisitor</a></td> |
|
59 <td>Class implementing a node visitor to check return statements.</td> |
|
60 </tr> |
|
61 <tr> |
|
62 <td><a href="#SysVersionVisitor">SysVersionVisitor</a></td> |
|
63 <td>Class implementing a node visitor to check the use of sys.version and sys.version_info.</td> |
|
64 </tr> |
|
65 <tr> |
|
66 <td><a href="#TextVisitor">TextVisitor</a></td> |
|
67 <td>Class implementing a node visitor for bytes and str instances.</td> |
|
68 </tr> |
|
69 </table> |
|
70 <h3>Functions</h3> |
|
71 |
|
72 <table> |
|
73 |
|
74 <tr> |
|
75 <td><a href="#composeCallPath">composeCallPath</a></td> |
|
76 <td>Generator function to assemble the call path of a given node.</td> |
|
77 </tr> |
|
78 </table> |
|
79 <hr /> |
|
80 <hr /> |
|
81 <a NAME="BugBearVisitor" ID="BugBearVisitor"></a> |
|
82 <h2>BugBearVisitor</h2> |
|
83 |
|
84 <p> |
|
85 Class implementing a node visitor to check for various topics. |
|
86 </p> |
|
87 <h3>Derived from</h3> |
|
88 ast.NodeVisitor |
|
89 <h3>Class Attributes</h3> |
|
90 |
|
91 <table> |
|
92 <tr><td>NodeWindowSize</td></tr> |
|
93 </table> |
|
94 <h3>Class Methods</h3> |
|
95 |
|
96 <table> |
|
97 <tr><td>None</td></tr> |
|
98 </table> |
|
99 <h3>Methods</h3> |
|
100 |
|
101 <table> |
|
102 |
|
103 <tr> |
|
104 <td><a href="#BugBearVisitor.__init__">BugBearVisitor</a></td> |
|
105 <td>Constructor</td> |
|
106 </tr> |
|
107 <tr> |
|
108 <td><a href="#BugBearVisitor.__checkForM502">__checkForM502</a></td> |
|
109 <td>Private method to check the use of *strip().</td> |
|
110 </tr> |
|
111 <tr> |
|
112 <td><a href="#BugBearVisitor.__checkForM507">__checkForM507</a></td> |
|
113 <td>Private method to check for unused loop variables.</td> |
|
114 </tr> |
|
115 <tr> |
|
116 <td><a href="#BugBearVisitor.visit">visit</a></td> |
|
117 <td>Public method to traverse a given AST node.</td> |
|
118 </tr> |
|
119 <tr> |
|
120 <td><a href="#BugBearVisitor.visit_Assert">visit_Assert</a></td> |
|
121 <td>Public method to handle 'assert' statements.</td> |
|
122 </tr> |
|
123 <tr> |
|
124 <td><a href="#BugBearVisitor.visit_Assign">visit_Assign</a></td> |
|
125 <td>Public method to handle assignments.</td> |
|
126 </tr> |
|
127 <tr> |
|
128 <td><a href="#BugBearVisitor.visit_AsyncFor">visit_AsyncFor</a></td> |
|
129 <td>Public method to handle 'for' statements.</td> |
|
130 </tr> |
|
131 <tr> |
|
132 <td><a href="#BugBearVisitor.visit_Attribute">visit_Attribute</a></td> |
|
133 <td>Public method to handle attributes.</td> |
|
134 </tr> |
|
135 <tr> |
|
136 <td><a href="#BugBearVisitor.visit_Call">visit_Call</a></td> |
|
137 <td>Public method to handle a function call.</td> |
|
138 </tr> |
|
139 <tr> |
|
140 <td><a href="#BugBearVisitor.visit_For">visit_For</a></td> |
|
141 <td>Public method to handle 'for' statements.</td> |
|
142 </tr> |
|
143 <tr> |
|
144 <td><a href="#BugBearVisitor.visit_JoinedStr">visit_JoinedStr</a></td> |
|
145 <td>Public method to handle f-string arguments.</td> |
|
146 </tr> |
|
147 <tr> |
|
148 <td><a href="#BugBearVisitor.visit_UAdd">visit_UAdd</a></td> |
|
149 <td>Public method to handle unary additions.</td> |
|
150 </tr> |
|
151 </table> |
|
152 <h3>Static Methods</h3> |
|
153 |
|
154 <table> |
|
155 <tr><td>None</td></tr> |
|
156 </table> |
|
157 |
|
158 <a NAME="BugBearVisitor.__init__" ID="BugBearVisitor.__init__"></a> |
|
159 <h4>BugBearVisitor (Constructor)</h4> |
|
160 <b>BugBearVisitor</b>(<i></i>) |
|
161 |
|
162 <p> |
|
163 Constructor |
|
164 </p> |
|
165 <a NAME="BugBearVisitor.__checkForM502" ID="BugBearVisitor.__checkForM502"></a> |
|
166 <h4>BugBearVisitor.__checkForM502</h4> |
|
167 <b>__checkForM502</b>(<i>node</i>) |
|
168 |
|
169 <p> |
|
170 Private method to check the use of *strip(). |
|
171 </p> |
|
172 <dl> |
|
173 |
|
174 <dt><i>node</i> (ast.Call)</dt> |
|
175 <dd> |
|
176 reference to the node to be processed |
|
177 </dd> |
|
178 </dl> |
|
179 <a NAME="BugBearVisitor.__checkForM507" ID="BugBearVisitor.__checkForM507"></a> |
|
180 <h4>BugBearVisitor.__checkForM507</h4> |
|
181 <b>__checkForM507</b>(<i>node</i>) |
|
182 |
|
183 <p> |
|
184 Private method to check for unused loop variables. |
|
185 </p> |
|
186 <dl> |
|
187 |
|
188 <dt><i>node</i> (ast.For)</dt> |
|
189 <dd> |
|
190 reference to the node to be processed |
|
191 </dd> |
|
192 </dl> |
|
193 <a NAME="BugBearVisitor.visit" ID="BugBearVisitor.visit"></a> |
|
194 <h4>BugBearVisitor.visit</h4> |
|
195 <b>visit</b>(<i>node</i>) |
|
196 |
|
197 <p> |
|
198 Public method to traverse a given AST node. |
|
199 </p> |
|
200 <dl> |
|
201 |
|
202 <dt><i>node</i> (ast.Node)</dt> |
|
203 <dd> |
|
204 AST node to be traversed |
|
205 </dd> |
|
206 </dl> |
|
207 <a NAME="BugBearVisitor.visit_Assert" ID="BugBearVisitor.visit_Assert"></a> |
|
208 <h4>BugBearVisitor.visit_Assert</h4> |
|
209 <b>visit_Assert</b>(<i>node</i>) |
|
210 |
|
211 <p> |
|
212 Public method to handle 'assert' statements. |
|
213 </p> |
|
214 <dl> |
|
215 |
|
216 <dt><i>node</i> (ast.Assert)</dt> |
|
217 <dd> |
|
218 reference to the node to be processed |
|
219 </dd> |
|
220 </dl> |
|
221 <a NAME="BugBearVisitor.visit_Assign" ID="BugBearVisitor.visit_Assign"></a> |
|
222 <h4>BugBearVisitor.visit_Assign</h4> |
|
223 <b>visit_Assign</b>(<i>node</i>) |
|
224 |
|
225 <p> |
|
226 Public method to handle assignments. |
|
227 </p> |
|
228 <dl> |
|
229 |
|
230 <dt><i>node</i> (ast.Assign)</dt> |
|
231 <dd> |
|
232 reference to the node to be processed |
|
233 </dd> |
|
234 </dl> |
|
235 <a NAME="BugBearVisitor.visit_AsyncFor" ID="BugBearVisitor.visit_AsyncFor"></a> |
|
236 <h4>BugBearVisitor.visit_AsyncFor</h4> |
|
237 <b>visit_AsyncFor</b>(<i>node</i>) |
|
238 |
|
239 <p> |
|
240 Public method to handle 'for' statements. |
|
241 </p> |
|
242 <dl> |
|
243 |
|
244 <dt><i>node</i> (ast.AsyncFor)</dt> |
|
245 <dd> |
|
246 reference to the node to be processed |
|
247 </dd> |
|
248 </dl> |
|
249 <a NAME="BugBearVisitor.visit_Attribute" ID="BugBearVisitor.visit_Attribute"></a> |
|
250 <h4>BugBearVisitor.visit_Attribute</h4> |
|
251 <b>visit_Attribute</b>(<i>node</i>) |
|
252 |
|
253 <p> |
|
254 Public method to handle attributes. |
|
255 </p> |
|
256 <dl> |
|
257 |
|
258 <dt><i>node</i> (ast.Attribute)</dt> |
|
259 <dd> |
|
260 reference to the node to be processed |
|
261 </dd> |
|
262 </dl> |
|
263 <a NAME="BugBearVisitor.visit_Call" ID="BugBearVisitor.visit_Call"></a> |
|
264 <h4>BugBearVisitor.visit_Call</h4> |
|
265 <b>visit_Call</b>(<i>node</i>) |
|
266 |
|
267 <p> |
|
268 Public method to handle a function call. |
|
269 </p> |
|
270 <dl> |
|
271 |
|
272 <dt><i>node</i> (ast.Call)</dt> |
|
273 <dd> |
|
274 reference to the node to be processed |
|
275 </dd> |
|
276 </dl> |
|
277 <a NAME="BugBearVisitor.visit_For" ID="BugBearVisitor.visit_For"></a> |
|
278 <h4>BugBearVisitor.visit_For</h4> |
|
279 <b>visit_For</b>(<i>node</i>) |
|
280 |
|
281 <p> |
|
282 Public method to handle 'for' statements. |
|
283 </p> |
|
284 <dl> |
|
285 |
|
286 <dt><i>node</i> (ast.For)</dt> |
|
287 <dd> |
|
288 reference to the node to be processed |
|
289 </dd> |
|
290 </dl> |
|
291 <a NAME="BugBearVisitor.visit_JoinedStr" ID="BugBearVisitor.visit_JoinedStr"></a> |
|
292 <h4>BugBearVisitor.visit_JoinedStr</h4> |
|
293 <b>visit_JoinedStr</b>(<i>node</i>) |
|
294 |
|
295 <p> |
|
296 Public method to handle f-string arguments. |
|
297 </p> |
|
298 <dl> |
|
299 |
|
300 <dt><i>node</i> (ast.JoinedStr)</dt> |
|
301 <dd> |
|
302 reference to the node to be processed |
|
303 </dd> |
|
304 </dl> |
|
305 <a NAME="BugBearVisitor.visit_UAdd" ID="BugBearVisitor.visit_UAdd"></a> |
|
306 <h4>BugBearVisitor.visit_UAdd</h4> |
|
307 <b>visit_UAdd</b>(<i>node</i>) |
|
308 |
|
309 <p> |
|
310 Public method to handle unary additions. |
|
311 </p> |
|
312 <dl> |
|
313 |
|
314 <dt><i>node</i> (ast.UAdd)</dt> |
|
315 <dd> |
|
316 reference to the node to be processed |
|
317 </dd> |
|
318 </dl> |
|
319 <div align="right"><a href="#top">Up</a></div> |
|
320 <hr /> |
|
321 <hr /> |
|
322 <a NAME="DateTimeVisitor" ID="DateTimeVisitor"></a> |
|
323 <h2>DateTimeVisitor</h2> |
|
324 |
|
325 <p> |
|
326 Class implementing a node visitor to check datetime function calls. |
|
327 </p> |
|
328 <p> |
|
329 Note: This class is modelled after flake8_datetimez checker. |
|
330 </p> |
|
331 <h3>Derived from</h3> |
|
332 ast.NodeVisitor |
|
333 <h3>Class Attributes</h3> |
|
334 |
|
335 <table> |
|
336 <tr><td>None</td></tr> |
|
337 </table> |
|
338 <h3>Class Methods</h3> |
|
339 |
|
340 <table> |
|
341 <tr><td>None</td></tr> |
|
342 </table> |
|
343 <h3>Methods</h3> |
|
344 |
|
345 <table> |
|
346 |
|
347 <tr> |
|
348 <td><a href="#DateTimeVisitor.__init__">DateTimeVisitor</a></td> |
|
349 <td>Constructor</td> |
|
350 </tr> |
|
351 <tr> |
|
352 <td><a href="#DateTimeVisitor.__getFromKeywords">__getFromKeywords</a></td> |
|
353 <td>Private method to get a keyword node given its name.</td> |
|
354 </tr> |
|
355 <tr> |
|
356 <td><a href="#DateTimeVisitor.visit_Call">visit_Call</a></td> |
|
357 <td>Public method to handle a function call.</td> |
|
358 </tr> |
|
359 </table> |
|
360 <h3>Static Methods</h3> |
|
361 |
|
362 <table> |
|
363 <tr><td>None</td></tr> |
|
364 </table> |
|
365 |
|
366 <a NAME="DateTimeVisitor.__init__" ID="DateTimeVisitor.__init__"></a> |
|
367 <h4>DateTimeVisitor (Constructor)</h4> |
|
368 <b>DateTimeVisitor</b>(<i></i>) |
|
369 |
|
370 <p> |
|
371 Constructor |
|
372 </p> |
|
373 <a NAME="DateTimeVisitor.__getFromKeywords" ID="DateTimeVisitor.__getFromKeywords"></a> |
|
374 <h4>DateTimeVisitor.__getFromKeywords</h4> |
|
375 <b>__getFromKeywords</b>(<i>keywords, name</i>) |
|
376 |
|
377 <p> |
|
378 Private method to get a keyword node given its name. |
|
379 </p> |
|
380 <dl> |
|
381 |
|
382 <dt><i>keywords</i> (list of ast.AST)</dt> |
|
383 <dd> |
|
384 list of keyword argument nodes |
|
385 </dd> |
|
386 <dt><i>name</i> (str)</dt> |
|
387 <dd> |
|
388 name of the keyword node |
|
389 </dd> |
|
390 </dl> |
|
391 <dl> |
|
392 <dt>Return:</dt> |
|
393 <dd> |
|
394 keyword node |
|
395 </dd> |
|
396 </dl> |
|
397 <dl> |
|
398 <dt>Return Type:</dt> |
|
399 <dd> |
|
400 ast.AST |
|
401 </dd> |
|
402 </dl> |
|
403 <a NAME="DateTimeVisitor.visit_Call" ID="DateTimeVisitor.visit_Call"></a> |
|
404 <h4>DateTimeVisitor.visit_Call</h4> |
|
405 <b>visit_Call</b>(<i>node</i>) |
|
406 |
|
407 <p> |
|
408 Public method to handle a function call. |
|
409 </p> |
|
410 <p> |
|
411 Every datetime related function call is check for use of the naive |
|
412 variant (i.e. use without TZ info). |
|
413 </p> |
|
414 <dl> |
|
415 |
|
416 <dt><i>node</i> (ast.Call)</dt> |
|
417 <dd> |
|
418 reference to the node to be processed |
|
419 </dd> |
|
420 </dl> |
|
421 <div align="right"><a href="#top">Up</a></div> |
|
422 <hr /> |
|
423 <hr /> |
|
424 <a NAME="LoggingVisitor" ID="LoggingVisitor"></a> |
|
425 <h2>LoggingVisitor</h2> |
|
426 |
|
427 <p> |
|
428 Class implementing a node visitor to check logging statements. |
|
429 </p> |
|
430 <h3>Derived from</h3> |
|
431 ast.NodeVisitor |
|
432 <h3>Class Attributes</h3> |
|
433 |
|
434 <table> |
|
435 <tr><td>LoggingLevels</td></tr> |
|
436 </table> |
|
437 <h3>Class Methods</h3> |
|
438 |
|
439 <table> |
|
440 <tr><td>None</td></tr> |
|
441 </table> |
|
442 <h3>Methods</h3> |
|
443 |
|
444 <table> |
|
445 |
|
446 <tr> |
|
447 <td><a href="#LoggingVisitor.__init__">LoggingVisitor</a></td> |
|
448 <td>Constructor</td> |
|
449 </tr> |
|
450 <tr> |
|
451 <td><a href="#LoggingVisitor.__detectLoggingLevel">__detectLoggingLevel</a></td> |
|
452 <td>Private method to decide whether an AST Call is a logging call.</td> |
|
453 </tr> |
|
454 <tr> |
|
455 <td><a href="#LoggingVisitor.__isFormatCall">__isFormatCall</a></td> |
|
456 <td>Private method to check if a function call uses format.</td> |
|
457 </tr> |
|
458 <tr> |
|
459 <td><a href="#LoggingVisitor.__withinExtraKeyword">__withinExtraKeyword</a></td> |
|
460 <td>Private method to check, if we are inside the extra keyword.</td> |
|
461 </tr> |
|
462 <tr> |
|
463 <td><a href="#LoggingVisitor.__withinLoggingArgument">__withinLoggingArgument</a></td> |
|
464 <td>Private method to check, if we are inside a logging argument.</td> |
|
465 </tr> |
|
466 <tr> |
|
467 <td><a href="#LoggingVisitor.__withinLoggingStatement">__withinLoggingStatement</a></td> |
|
468 <td>Private method to check, if we are inside a logging statement.</td> |
|
469 </tr> |
|
470 <tr> |
|
471 <td><a href="#LoggingVisitor.visit_BinOp">visit_BinOp</a></td> |
|
472 <td>Public method to handle binary operations while processing the first logging argument.</td> |
|
473 </tr> |
|
474 <tr> |
|
475 <td><a href="#LoggingVisitor.visit_Call">visit_Call</a></td> |
|
476 <td>Public method to handle a function call.</td> |
|
477 </tr> |
|
478 <tr> |
|
479 <td><a href="#LoggingVisitor.visit_JoinedStr">visit_JoinedStr</a></td> |
|
480 <td>Public method to handle f-string arguments.</td> |
|
481 </tr> |
|
482 </table> |
|
483 <h3>Static Methods</h3> |
|
484 |
|
485 <table> |
|
486 <tr><td>None</td></tr> |
|
487 </table> |
|
488 |
|
489 <a NAME="LoggingVisitor.__init__" ID="LoggingVisitor.__init__"></a> |
|
490 <h4>LoggingVisitor (Constructor)</h4> |
|
491 <b>LoggingVisitor</b>(<i></i>) |
|
492 |
|
493 <p> |
|
494 Constructor |
|
495 </p> |
|
496 <a NAME="LoggingVisitor.__detectLoggingLevel" ID="LoggingVisitor.__detectLoggingLevel"></a> |
|
497 <h4>LoggingVisitor.__detectLoggingLevel</h4> |
|
498 <b>__detectLoggingLevel</b>(<i>node</i>) |
|
499 |
|
500 <p> |
|
501 Private method to decide whether an AST Call is a logging call. |
|
502 </p> |
|
503 <dl> |
|
504 |
|
505 <dt><i>node</i> (ast.Call)</dt> |
|
506 <dd> |
|
507 reference to the node to be processed |
|
508 </dd> |
|
509 </dl> |
|
510 <dl> |
|
511 <dt>Return:</dt> |
|
512 <dd> |
|
513 logging level |
|
514 </dd> |
|
515 </dl> |
|
516 <dl> |
|
517 <dt>Return Type:</dt> |
|
518 <dd> |
|
519 str or None |
|
520 </dd> |
|
521 </dl> |
|
522 <a NAME="LoggingVisitor.__isFormatCall" ID="LoggingVisitor.__isFormatCall"></a> |
|
523 <h4>LoggingVisitor.__isFormatCall</h4> |
|
524 <b>__isFormatCall</b>(<i>node</i>) |
|
525 |
|
526 <p> |
|
527 Private method to check if a function call uses format. |
|
528 </p> |
|
529 <dl> |
|
530 |
|
531 <dt><i>node</i> (ast.Call)</dt> |
|
532 <dd> |
|
533 reference to the node to be processed |
|
534 </dd> |
|
535 </dl> |
|
536 <dl> |
|
537 <dt>Return:</dt> |
|
538 <dd> |
|
539 flag indicating the function call uses format |
|
540 </dd> |
|
541 </dl> |
|
542 <dl> |
|
543 <dt>Return Type:</dt> |
|
544 <dd> |
|
545 bool |
|
546 </dd> |
|
547 </dl> |
|
548 <a NAME="LoggingVisitor.__withinExtraKeyword" ID="LoggingVisitor.__withinExtraKeyword"></a> |
|
549 <h4>LoggingVisitor.__withinExtraKeyword</h4> |
|
550 <b>__withinExtraKeyword</b>(<i>node</i>) |
|
551 |
|
552 <p> |
|
553 Private method to check, if we are inside the extra keyword. |
|
554 </p> |
|
555 <dl> |
|
556 |
|
557 <dt><i>node</i> (ast.keyword)</dt> |
|
558 <dd> |
|
559 reference to the node to be checked |
|
560 </dd> |
|
561 </dl> |
|
562 <dl> |
|
563 <dt>Return:</dt> |
|
564 <dd> |
|
565 flag indicating we are inside the extra keyword |
|
566 </dd> |
|
567 </dl> |
|
568 <dl> |
|
569 <dt>Return Type:</dt> |
|
570 <dd> |
|
571 bool |
|
572 </dd> |
|
573 </dl> |
|
574 <a NAME="LoggingVisitor.__withinLoggingArgument" ID="LoggingVisitor.__withinLoggingArgument"></a> |
|
575 <h4>LoggingVisitor.__withinLoggingArgument</h4> |
|
576 <b>__withinLoggingArgument</b>(<i></i>) |
|
577 |
|
578 <p> |
|
579 Private method to check, if we are inside a logging argument. |
|
580 </p> |
|
581 <dl> |
|
582 <dt>Return:</dt> |
|
583 <dd> |
|
584 flag indicating we are inside a logging argument |
|
585 </dd> |
|
586 </dl> |
|
587 <dl> |
|
588 <dt>Return Type:</dt> |
|
589 <dd> |
|
590 bool |
|
591 </dd> |
|
592 </dl> |
|
593 <a NAME="LoggingVisitor.__withinLoggingStatement" ID="LoggingVisitor.__withinLoggingStatement"></a> |
|
594 <h4>LoggingVisitor.__withinLoggingStatement</h4> |
|
595 <b>__withinLoggingStatement</b>(<i></i>) |
|
596 |
|
597 <p> |
|
598 Private method to check, if we are inside a logging statement. |
|
599 </p> |
|
600 <dl> |
|
601 <dt>Return:</dt> |
|
602 <dd> |
|
603 flag indicating we are inside a logging statement |
|
604 </dd> |
|
605 </dl> |
|
606 <dl> |
|
607 <dt>Return Type:</dt> |
|
608 <dd> |
|
609 bool |
|
610 </dd> |
|
611 </dl> |
|
612 <a NAME="LoggingVisitor.visit_BinOp" ID="LoggingVisitor.visit_BinOp"></a> |
|
613 <h4>LoggingVisitor.visit_BinOp</h4> |
|
614 <b>visit_BinOp</b>(<i>node</i>) |
|
615 |
|
616 <p> |
|
617 Public method to handle binary operations while processing the first |
|
618 logging argument. |
|
619 </p> |
|
620 <dl> |
|
621 |
|
622 <dt><i>node</i> (ast.BinOp)</dt> |
|
623 <dd> |
|
624 reference to the node to be processed |
|
625 </dd> |
|
626 </dl> |
|
627 <a NAME="LoggingVisitor.visit_Call" ID="LoggingVisitor.visit_Call"></a> |
|
628 <h4>LoggingVisitor.visit_Call</h4> |
|
629 <b>visit_Call</b>(<i>node</i>) |
|
630 |
|
631 <p> |
|
632 Public method to handle a function call. |
|
633 </p> |
|
634 <p> |
|
635 Every logging statement and string format is expected to be a function |
|
636 call. |
|
637 </p> |
|
638 <dl> |
|
639 |
|
640 <dt><i>node</i> (ast.Call)</dt> |
|
641 <dd> |
|
642 reference to the node to be processed |
|
643 </dd> |
|
644 </dl> |
|
645 <a NAME="LoggingVisitor.visit_JoinedStr" ID="LoggingVisitor.visit_JoinedStr"></a> |
|
646 <h4>LoggingVisitor.visit_JoinedStr</h4> |
|
647 <b>visit_JoinedStr</b>(<i>node</i>) |
|
648 |
|
649 <p> |
|
650 Public method to handle f-string arguments. |
|
651 </p> |
|
652 <dl> |
|
653 |
|
654 <dt><i>node</i> (ast.JoinedStr)</dt> |
|
655 <dd> |
|
656 reference to the node to be processed |
|
657 </dd> |
|
658 </dl> |
|
659 <div align="right"><a href="#top">Up</a></div> |
|
660 <hr /> |
|
661 <hr /> |
|
662 <a NAME="MiscellaneousChecker" ID="MiscellaneousChecker"></a> |
|
663 <h2>MiscellaneousChecker</h2> |
|
664 |
|
665 <p> |
|
666 Class implementing a checker for miscellaneous checks. |
|
667 </p> |
|
668 <h3>Derived from</h3> |
|
669 None |
|
670 <h3>Class Attributes</h3> |
|
671 |
|
672 <table> |
|
673 <tr><td>BuiltinsWhiteList</td></tr><tr><td>Codes</td></tr><tr><td>FormatFieldRegex</td></tr><tr><td>Formatter</td></tr> |
|
674 </table> |
|
675 <h3>Class Methods</h3> |
|
676 |
|
677 <table> |
|
678 <tr><td>None</td></tr> |
|
679 </table> |
|
680 <h3>Methods</h3> |
|
681 |
|
682 <table> |
|
683 |
|
684 <tr> |
|
685 <td><a href="#MiscellaneousChecker.__init__">MiscellaneousChecker</a></td> |
|
686 <td>Constructor</td> |
|
687 </tr> |
|
688 <tr> |
|
689 <td><a href="#MiscellaneousChecker.__checkBugBear">__checkBugBear</a></td> |
|
690 <td>Private method for bugbear checks.</td> |
|
691 </tr> |
|
692 <tr> |
|
693 <td><a href="#MiscellaneousChecker.__checkBuiltins">__checkBuiltins</a></td> |
|
694 <td>Private method to check, if built-ins are shadowed.</td> |
|
695 </tr> |
|
696 <tr> |
|
697 <td><a href="#MiscellaneousChecker.__checkCoding">__checkCoding</a></td> |
|
698 <td>Private method to check the presence of a coding line and valid encodings.</td> |
|
699 </tr> |
|
700 <tr> |
|
701 <td><a href="#MiscellaneousChecker.__checkCommentedCode">__checkCommentedCode</a></td> |
|
702 <td>Private method to check for commented code.</td> |
|
703 </tr> |
|
704 <tr> |
|
705 <td><a href="#MiscellaneousChecker.__checkComprehensions">__checkComprehensions</a></td> |
|
706 <td>Private method to check some comprehension related things.</td> |
|
707 </tr> |
|
708 <tr> |
|
709 <td><a href="#MiscellaneousChecker.__checkCopyright">__checkCopyright</a></td> |
|
710 <td>Private method to check the presence of a copyright statement.</td> |
|
711 </tr> |
|
712 <tr> |
|
713 <td><a href="#MiscellaneousChecker.__checkDateTime">__checkDateTime</a></td> |
|
714 <td>Private method to check use of naive datetime functions.</td> |
|
715 </tr> |
|
716 <tr> |
|
717 <td><a href="#MiscellaneousChecker.__checkDictWithSortedKeys">__checkDictWithSortedKeys</a></td> |
|
718 <td>Private method to check, if dictionary keys appear in sorted order.</td> |
|
719 </tr> |
|
720 <tr> |
|
721 <td><a href="#MiscellaneousChecker.__checkFormatString">__checkFormatString</a></td> |
|
722 <td>Private method to check string format strings.</td> |
|
723 </tr> |
|
724 <tr> |
|
725 <td><a href="#MiscellaneousChecker.__checkFuture">__checkFuture</a></td> |
|
726 <td>Private method to check the __future__ imports.</td> |
|
727 </tr> |
|
728 <tr> |
|
729 <td><a href="#MiscellaneousChecker.__checkGettext">__checkGettext</a></td> |
|
730 <td>Private method to check the 'gettext' import statement.</td> |
|
731 </tr> |
|
732 <tr> |
|
733 <td><a href="#MiscellaneousChecker.__checkLineContinuation">__checkLineContinuation</a></td> |
|
734 <td>Private method to check line continuation using backslash.</td> |
|
735 </tr> |
|
736 <tr> |
|
737 <td><a href="#MiscellaneousChecker.__checkLogging">__checkLogging</a></td> |
|
738 <td>Private method to check logging statements.</td> |
|
739 </tr> |
|
740 <tr> |
|
741 <td><a href="#MiscellaneousChecker.__checkMutableDefault">__checkMutableDefault</a></td> |
|
742 <td>Private method to check for use of mutable types as default arguments.</td> |
|
743 </tr> |
|
744 <tr> |
|
745 <td><a href="#MiscellaneousChecker.__checkPep3101">__checkPep3101</a></td> |
|
746 <td>Private method to check for old style string formatting.</td> |
|
747 </tr> |
|
748 <tr> |
|
749 <td><a href="#MiscellaneousChecker.__checkPrintStatements">__checkPrintStatements</a></td> |
|
750 <td>Private method to check for print statements.</td> |
|
751 </tr> |
|
752 <tr> |
|
753 <td><a href="#MiscellaneousChecker.__checkReturn">__checkReturn</a></td> |
|
754 <td>Private method to check return statements.</td> |
|
755 </tr> |
|
756 <tr> |
|
757 <td><a href="#MiscellaneousChecker.__checkSysVersion">__checkSysVersion</a></td> |
|
758 <td>Private method to check the use of sys.version and sys.version_info.</td> |
|
759 </tr> |
|
760 <tr> |
|
761 <td><a href="#MiscellaneousChecker.__checkTuple">__checkTuple</a></td> |
|
762 <td>Private method to check for one element tuples.</td> |
|
763 </tr> |
|
764 <tr> |
|
765 <td><a href="#MiscellaneousChecker.__dictShouldBeChecked">__dictShouldBeChecked</a></td> |
|
766 <td>Private function to test, if the node should be checked.</td> |
|
767 </tr> |
|
768 <tr> |
|
769 <td><a href="#MiscellaneousChecker.__error">__error</a></td> |
|
770 <td>Private method to record an issue.</td> |
|
771 </tr> |
|
772 <tr> |
|
773 <td><a href="#MiscellaneousChecker.__getCoding">__getCoding</a></td> |
|
774 <td>Private method to get the defined coding of the source.</td> |
|
775 </tr> |
|
776 <tr> |
|
777 <td><a href="#MiscellaneousChecker.__getFields">__getFields</a></td> |
|
778 <td>Private method to extract the format field information.</td> |
|
779 </tr> |
|
780 <tr> |
|
781 <td><a href="#MiscellaneousChecker.__ignoreCode">__ignoreCode</a></td> |
|
782 <td>Private method to check if the message code should be ignored.</td> |
|
783 </tr> |
|
784 <tr> |
|
785 <td><a href="#MiscellaneousChecker.run">run</a></td> |
|
786 <td>Public method to check the given source against miscellaneous conditions.</td> |
|
787 </tr> |
|
788 </table> |
|
789 <h3>Static Methods</h3> |
|
790 |
|
791 <table> |
|
792 <tr><td>None</td></tr> |
|
793 </table> |
|
794 |
|
795 <a NAME="MiscellaneousChecker.__init__" ID="MiscellaneousChecker.__init__"></a> |
|
796 <h4>MiscellaneousChecker (Constructor)</h4> |
|
797 <b>MiscellaneousChecker</b>(<i>source, filename, tree, select, ignore, expected, repeat, args</i>) |
|
798 |
|
799 <p> |
|
800 Constructor |
|
801 </p> |
|
802 <dl> |
|
803 |
|
804 <dt><i>source</i> (list of str)</dt> |
|
805 <dd> |
|
806 source code to be checked |
|
807 </dd> |
|
808 <dt><i>filename</i> (str)</dt> |
|
809 <dd> |
|
810 name of the source file |
|
811 </dd> |
|
812 <dt><i>tree</i> (ast.Module)</dt> |
|
813 <dd> |
|
814 AST tree of the source code |
|
815 </dd> |
|
816 <dt><i>select</i> (list of str)</dt> |
|
817 <dd> |
|
818 list of selected codes |
|
819 </dd> |
|
820 <dt><i>ignore</i> (list of str)</dt> |
|
821 <dd> |
|
822 list of codes to be ignored |
|
823 </dd> |
|
824 <dt><i>expected</i> (list of str)</dt> |
|
825 <dd> |
|
826 list of expected codes |
|
827 </dd> |
|
828 <dt><i>repeat</i> (bool)</dt> |
|
829 <dd> |
|
830 flag indicating to report each occurrence of a code |
|
831 </dd> |
|
832 <dt><i>args</i> (dict)</dt> |
|
833 <dd> |
|
834 dictionary of arguments for the miscellaneous checks |
|
835 </dd> |
|
836 </dl> |
|
837 <a NAME="MiscellaneousChecker.__checkBugBear" ID="MiscellaneousChecker.__checkBugBear"></a> |
|
838 <h4>MiscellaneousChecker.__checkBugBear</h4> |
|
839 <b>__checkBugBear</b>(<i></i>) |
|
840 |
|
841 <p> |
|
842 Private method for bugbear checks. |
|
843 </p> |
|
844 <a NAME="MiscellaneousChecker.__checkBuiltins" ID="MiscellaneousChecker.__checkBuiltins"></a> |
|
845 <h4>MiscellaneousChecker.__checkBuiltins</h4> |
|
846 <b>__checkBuiltins</b>(<i></i>) |
|
847 |
|
848 <p> |
|
849 Private method to check, if built-ins are shadowed. |
|
850 </p> |
|
851 <a NAME="MiscellaneousChecker.__checkCoding" ID="MiscellaneousChecker.__checkCoding"></a> |
|
852 <h4>MiscellaneousChecker.__checkCoding</h4> |
|
853 <b>__checkCoding</b>(<i></i>) |
|
854 |
|
855 <p> |
|
856 Private method to check the presence of a coding line and valid |
|
857 encodings. |
|
858 </p> |
|
859 <a NAME="MiscellaneousChecker.__checkCommentedCode" ID="MiscellaneousChecker.__checkCommentedCode"></a> |
|
860 <h4>MiscellaneousChecker.__checkCommentedCode</h4> |
|
861 <b>__checkCommentedCode</b>(<i></i>) |
|
862 |
|
863 <p> |
|
864 Private method to check for commented code. |
|
865 </p> |
|
866 <a NAME="MiscellaneousChecker.__checkComprehensions" ID="MiscellaneousChecker.__checkComprehensions"></a> |
|
867 <h4>MiscellaneousChecker.__checkComprehensions</h4> |
|
868 <b>__checkComprehensions</b>(<i></i>) |
|
869 |
|
870 <p> |
|
871 Private method to check some comprehension related things. |
|
872 </p> |
|
873 <a NAME="MiscellaneousChecker.__checkCopyright" ID="MiscellaneousChecker.__checkCopyright"></a> |
|
874 <h4>MiscellaneousChecker.__checkCopyright</h4> |
|
875 <b>__checkCopyright</b>(<i></i>) |
|
876 |
|
877 <p> |
|
878 Private method to check the presence of a copyright statement. |
|
879 </p> |
|
880 <a NAME="MiscellaneousChecker.__checkDateTime" ID="MiscellaneousChecker.__checkDateTime"></a> |
|
881 <h4>MiscellaneousChecker.__checkDateTime</h4> |
|
882 <b>__checkDateTime</b>(<i></i>) |
|
883 |
|
884 <p> |
|
885 Private method to check use of naive datetime functions. |
|
886 </p> |
|
887 <a NAME="MiscellaneousChecker.__checkDictWithSortedKeys" ID="MiscellaneousChecker.__checkDictWithSortedKeys"></a> |
|
888 <h4>MiscellaneousChecker.__checkDictWithSortedKeys</h4> |
|
889 <b>__checkDictWithSortedKeys</b>(<i></i>) |
|
890 |
|
891 <p> |
|
892 Private method to check, if dictionary keys appear in sorted order. |
|
893 </p> |
|
894 <a NAME="MiscellaneousChecker.__checkFormatString" ID="MiscellaneousChecker.__checkFormatString"></a> |
|
895 <h4>MiscellaneousChecker.__checkFormatString</h4> |
|
896 <b>__checkFormatString</b>(<i></i>) |
|
897 |
|
898 <p> |
|
899 Private method to check string format strings. |
|
900 </p> |
|
901 <a NAME="MiscellaneousChecker.__checkFuture" ID="MiscellaneousChecker.__checkFuture"></a> |
|
902 <h4>MiscellaneousChecker.__checkFuture</h4> |
|
903 <b>__checkFuture</b>(<i></i>) |
|
904 |
|
905 <p> |
|
906 Private method to check the __future__ imports. |
|
907 </p> |
|
908 <a NAME="MiscellaneousChecker.__checkGettext" ID="MiscellaneousChecker.__checkGettext"></a> |
|
909 <h4>MiscellaneousChecker.__checkGettext</h4> |
|
910 <b>__checkGettext</b>(<i></i>) |
|
911 |
|
912 <p> |
|
913 Private method to check the 'gettext' import statement. |
|
914 </p> |
|
915 <a NAME="MiscellaneousChecker.__checkLineContinuation" ID="MiscellaneousChecker.__checkLineContinuation"></a> |
|
916 <h4>MiscellaneousChecker.__checkLineContinuation</h4> |
|
917 <b>__checkLineContinuation</b>(<i></i>) |
|
918 |
|
919 <p> |
|
920 Private method to check line continuation using backslash. |
|
921 </p> |
|
922 <a NAME="MiscellaneousChecker.__checkLogging" ID="MiscellaneousChecker.__checkLogging"></a> |
|
923 <h4>MiscellaneousChecker.__checkLogging</h4> |
|
924 <b>__checkLogging</b>(<i></i>) |
|
925 |
|
926 <p> |
|
927 Private method to check logging statements. |
|
928 </p> |
|
929 <a NAME="MiscellaneousChecker.__checkMutableDefault" ID="MiscellaneousChecker.__checkMutableDefault"></a> |
|
930 <h4>MiscellaneousChecker.__checkMutableDefault</h4> |
|
931 <b>__checkMutableDefault</b>(<i></i>) |
|
932 |
|
933 <p> |
|
934 Private method to check for use of mutable types as default arguments. |
|
935 </p> |
|
936 <a NAME="MiscellaneousChecker.__checkPep3101" ID="MiscellaneousChecker.__checkPep3101"></a> |
|
937 <h4>MiscellaneousChecker.__checkPep3101</h4> |
|
938 <b>__checkPep3101</b>(<i></i>) |
|
939 |
|
940 <p> |
|
941 Private method to check for old style string formatting. |
|
942 </p> |
|
943 <a NAME="MiscellaneousChecker.__checkPrintStatements" ID="MiscellaneousChecker.__checkPrintStatements"></a> |
|
944 <h4>MiscellaneousChecker.__checkPrintStatements</h4> |
|
945 <b>__checkPrintStatements</b>(<i></i>) |
|
946 |
|
947 <p> |
|
948 Private method to check for print statements. |
|
949 </p> |
|
950 <a NAME="MiscellaneousChecker.__checkReturn" ID="MiscellaneousChecker.__checkReturn"></a> |
|
951 <h4>MiscellaneousChecker.__checkReturn</h4> |
|
952 <b>__checkReturn</b>(<i></i>) |
|
953 |
|
954 <p> |
|
955 Private method to check return statements. |
|
956 </p> |
|
957 <a NAME="MiscellaneousChecker.__checkSysVersion" ID="MiscellaneousChecker.__checkSysVersion"></a> |
|
958 <h4>MiscellaneousChecker.__checkSysVersion</h4> |
|
959 <b>__checkSysVersion</b>(<i></i>) |
|
960 |
|
961 <p> |
|
962 Private method to check the use of sys.version and sys.version_info. |
|
963 </p> |
|
964 <a NAME="MiscellaneousChecker.__checkTuple" ID="MiscellaneousChecker.__checkTuple"></a> |
|
965 <h4>MiscellaneousChecker.__checkTuple</h4> |
|
966 <b>__checkTuple</b>(<i></i>) |
|
967 |
|
968 <p> |
|
969 Private method to check for one element tuples. |
|
970 </p> |
|
971 <a NAME="MiscellaneousChecker.__dictShouldBeChecked" ID="MiscellaneousChecker.__dictShouldBeChecked"></a> |
|
972 <h4>MiscellaneousChecker.__dictShouldBeChecked</h4> |
|
973 <b>__dictShouldBeChecked</b>(<i>node</i>) |
|
974 |
|
975 <p> |
|
976 Private function to test, if the node should be checked. |
|
977 </p> |
|
978 <dl> |
|
979 |
|
980 <dt><i>node</i></dt> |
|
981 <dd> |
|
982 reference to the AST node |
|
983 </dd> |
|
984 </dl> |
|
985 <dl> |
|
986 <dt>Return:</dt> |
|
987 <dd> |
|
988 flag indicating to check the node |
|
989 </dd> |
|
990 </dl> |
|
991 <dl> |
|
992 <dt>Return Type:</dt> |
|
993 <dd> |
|
994 bool |
|
995 </dd> |
|
996 </dl> |
|
997 <a NAME="MiscellaneousChecker.__error" ID="MiscellaneousChecker.__error"></a> |
|
998 <h4>MiscellaneousChecker.__error</h4> |
|
999 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
|
1000 |
|
1001 <p> |
|
1002 Private method to record an issue. |
|
1003 </p> |
|
1004 <dl> |
|
1005 |
|
1006 <dt><i>lineNumber</i> (int)</dt> |
|
1007 <dd> |
|
1008 line number of the issue |
|
1009 </dd> |
|
1010 <dt><i>offset</i> (int)</dt> |
|
1011 <dd> |
|
1012 position within line of the issue |
|
1013 </dd> |
|
1014 <dt><i>code</i> (str)</dt> |
|
1015 <dd> |
|
1016 message code |
|
1017 </dd> |
|
1018 <dt><i>args</i> (list)</dt> |
|
1019 <dd> |
|
1020 arguments for the message |
|
1021 </dd> |
|
1022 </dl> |
|
1023 <a NAME="MiscellaneousChecker.__getCoding" ID="MiscellaneousChecker.__getCoding"></a> |
|
1024 <h4>MiscellaneousChecker.__getCoding</h4> |
|
1025 <b>__getCoding</b>(<i></i>) |
|
1026 |
|
1027 <p> |
|
1028 Private method to get the defined coding of the source. |
|
1029 </p> |
|
1030 <dl> |
|
1031 <dt>Return:</dt> |
|
1032 <dd> |
|
1033 tuple containing the line number and the coding |
|
1034 </dd> |
|
1035 </dl> |
|
1036 <dl> |
|
1037 <dt>Return Type:</dt> |
|
1038 <dd> |
|
1039 tuple of int and str |
|
1040 </dd> |
|
1041 </dl> |
|
1042 <a NAME="MiscellaneousChecker.__getFields" ID="MiscellaneousChecker.__getFields"></a> |
|
1043 <h4>MiscellaneousChecker.__getFields</h4> |
|
1044 <b>__getFields</b>(<i>string</i>) |
|
1045 |
|
1046 <p> |
|
1047 Private method to extract the format field information. |
|
1048 </p> |
|
1049 <dl> |
|
1050 |
|
1051 <dt><i>string</i> (str)</dt> |
|
1052 <dd> |
|
1053 format string to be parsed |
|
1054 </dd> |
|
1055 </dl> |
|
1056 <dl> |
|
1057 <dt>Return:</dt> |
|
1058 <dd> |
|
1059 format field information as a tuple with fields, implicit |
|
1060 field definitions present and explicit field definitions present |
|
1061 </dd> |
|
1062 </dl> |
|
1063 <dl> |
|
1064 <dt>Return Type:</dt> |
|
1065 <dd> |
|
1066 tuple of set of str, bool, bool |
|
1067 </dd> |
|
1068 </dl> |
|
1069 <a NAME="MiscellaneousChecker.__ignoreCode" ID="MiscellaneousChecker.__ignoreCode"></a> |
|
1070 <h4>MiscellaneousChecker.__ignoreCode</h4> |
|
1071 <b>__ignoreCode</b>(<i>code</i>) |
|
1072 |
|
1073 <p> |
|
1074 Private method to check if the message code should be ignored. |
|
1075 </p> |
|
1076 <dl> |
|
1077 |
|
1078 <dt><i>code</i> (str)</dt> |
|
1079 <dd> |
|
1080 message code to check for |
|
1081 </dd> |
|
1082 </dl> |
|
1083 <dl> |
|
1084 <dt>Return:</dt> |
|
1085 <dd> |
|
1086 flag indicating to ignore the given code |
|
1087 </dd> |
|
1088 </dl> |
|
1089 <dl> |
|
1090 <dt>Return Type:</dt> |
|
1091 <dd> |
|
1092 bool |
|
1093 </dd> |
|
1094 </dl> |
|
1095 <a NAME="MiscellaneousChecker.run" ID="MiscellaneousChecker.run"></a> |
|
1096 <h4>MiscellaneousChecker.run</h4> |
|
1097 <b>run</b>(<i></i>) |
|
1098 |
|
1099 <p> |
|
1100 Public method to check the given source against miscellaneous |
|
1101 conditions. |
|
1102 </p> |
|
1103 <div align="right"><a href="#top">Up</a></div> |
|
1104 <hr /> |
|
1105 <hr /> |
|
1106 <a NAME="NameFinder" ID="NameFinder"></a> |
|
1107 <h2>NameFinder</h2> |
|
1108 |
|
1109 <p> |
|
1110 Class to extract a name out of a tree of nodes. |
|
1111 </p> |
|
1112 <h3>Derived from</h3> |
|
1113 ast.NodeVisitor |
|
1114 <h3>Class Attributes</h3> |
|
1115 |
|
1116 <table> |
|
1117 <tr><td>None</td></tr> |
|
1118 </table> |
|
1119 <h3>Class Methods</h3> |
|
1120 |
|
1121 <table> |
|
1122 <tr><td>None</td></tr> |
|
1123 </table> |
|
1124 <h3>Methods</h3> |
|
1125 |
|
1126 <table> |
|
1127 |
|
1128 <tr> |
|
1129 <td><a href="#NameFinder.__init__">NameFinder</a></td> |
|
1130 <td>Constructor</td> |
|
1131 </tr> |
|
1132 <tr> |
|
1133 <td><a href="#NameFinder.getNames">getNames</a></td> |
|
1134 <td>Public method to return the extracted names and Name nodes.</td> |
|
1135 </tr> |
|
1136 <tr> |
|
1137 <td><a href="#NameFinder.visit">visit</a></td> |
|
1138 <td>Public method to traverse a given AST node.</td> |
|
1139 </tr> |
|
1140 <tr> |
|
1141 <td><a href="#NameFinder.visit_Name">visit_Name</a></td> |
|
1142 <td>Public method to handle 'Name' nodes.</td> |
|
1143 </tr> |
|
1144 </table> |
|
1145 <h3>Static Methods</h3> |
|
1146 |
|
1147 <table> |
|
1148 <tr><td>None</td></tr> |
|
1149 </table> |
|
1150 |
|
1151 <a NAME="NameFinder.__init__" ID="NameFinder.__init__"></a> |
|
1152 <h4>NameFinder (Constructor)</h4> |
|
1153 <b>NameFinder</b>(<i></i>) |
|
1154 |
|
1155 <p> |
|
1156 Constructor |
|
1157 </p> |
|
1158 <a NAME="NameFinder.getNames" ID="NameFinder.getNames"></a> |
|
1159 <h4>NameFinder.getNames</h4> |
|
1160 <b>getNames</b>(<i></i>) |
|
1161 |
|
1162 <p> |
|
1163 Public method to return the extracted names and Name nodes. |
|
1164 </p> |
|
1165 <dl> |
|
1166 <dt>Return:</dt> |
|
1167 <dd> |
|
1168 dictionary containing the names as keys and the list of nodes |
|
1169 </dd> |
|
1170 </dl> |
|
1171 <dl> |
|
1172 <dt>Return Type:</dt> |
|
1173 <dd> |
|
1174 dict |
|
1175 </dd> |
|
1176 </dl> |
|
1177 <a NAME="NameFinder.visit" ID="NameFinder.visit"></a> |
|
1178 <h4>NameFinder.visit</h4> |
|
1179 <b>visit</b>(<i>node</i>) |
|
1180 |
|
1181 <p> |
|
1182 Public method to traverse a given AST node. |
|
1183 </p> |
|
1184 <dl> |
|
1185 |
|
1186 <dt><i>node</i> (ast.Node)</dt> |
|
1187 <dd> |
|
1188 AST node to be traversed |
|
1189 </dd> |
|
1190 </dl> |
|
1191 <a NAME="NameFinder.visit_Name" ID="NameFinder.visit_Name"></a> |
|
1192 <h4>NameFinder.visit_Name</h4> |
|
1193 <b>visit_Name</b>(<i>node</i>) |
|
1194 |
|
1195 <p> |
|
1196 Public method to handle 'Name' nodes. |
|
1197 </p> |
|
1198 <dl> |
|
1199 |
|
1200 <dt><i>node</i> (ast.Name)</dt> |
|
1201 <dd> |
|
1202 reference to the node to be processed |
|
1203 </dd> |
|
1204 </dl> |
|
1205 <div align="right"><a href="#top">Up</a></div> |
|
1206 <hr /> |
|
1207 <hr /> |
|
1208 <a NAME="ReturnVisitor" ID="ReturnVisitor"></a> |
|
1209 <h2>ReturnVisitor</h2> |
|
1210 |
|
1211 <p> |
|
1212 Class implementing a node visitor to check return statements. |
|
1213 </p> |
|
1214 <h3>Derived from</h3> |
|
1215 ast.NodeVisitor |
|
1216 <h3>Class Attributes</h3> |
|
1217 |
|
1218 <table> |
|
1219 <tr><td>Assigns</td></tr><tr><td>Refs</td></tr><tr><td>Returns</td></tr> |
|
1220 </table> |
|
1221 <h3>Class Methods</h3> |
|
1222 |
|
1223 <table> |
|
1224 <tr><td>None</td></tr> |
|
1225 </table> |
|
1226 <h3>Methods</h3> |
|
1227 |
|
1228 <table> |
|
1229 |
|
1230 <tr> |
|
1231 <td><a href="#ReturnVisitor.__init__">ReturnVisitor</a></td> |
|
1232 <td>Constructor</td> |
|
1233 </tr> |
|
1234 <tr> |
|
1235 <td><a href="#ReturnVisitor.__checkFunction">__checkFunction</a></td> |
|
1236 <td>Private method to check a function definition node.</td> |
|
1237 </tr> |
|
1238 <tr> |
|
1239 <td><a href="#ReturnVisitor.__checkImplicitReturn">__checkImplicitReturn</a></td> |
|
1240 <td>Private method to check for an implicit return statement.</td> |
|
1241 </tr> |
|
1242 <tr> |
|
1243 <td><a href="#ReturnVisitor.__checkImplicitReturnValue">__checkImplicitReturnValue</a></td> |
|
1244 <td>Private method to check for implicit return values.</td> |
|
1245 </tr> |
|
1246 <tr> |
|
1247 <td><a href="#ReturnVisitor.__checkUnnecessaryAssign">__checkUnnecessaryAssign</a></td> |
|
1248 <td>Private method to check for an unnecessary assign statement.</td> |
|
1249 </tr> |
|
1250 <tr> |
|
1251 <td><a href="#ReturnVisitor.__checkUnnecessaryReturnNone">__checkUnnecessaryReturnNone</a></td> |
|
1252 <td>Private method to check for an unnecessary 'return None' statement.</td> |
|
1253 </tr> |
|
1254 <tr> |
|
1255 <td><a href="#ReturnVisitor.__hasRefsBeforeNextAssign">__hasRefsBeforeNextAssign</a></td> |
|
1256 <td>Private method to check for references before a following assign statement.</td> |
|
1257 </tr> |
|
1258 <tr> |
|
1259 <td><a href="#ReturnVisitor.__isFalse">__isFalse</a></td> |
|
1260 <td>Private method to check, if a node value is False.</td> |
|
1261 </tr> |
|
1262 <tr> |
|
1263 <td><a href="#ReturnVisitor.__isNone">__isNone</a></td> |
|
1264 <td>Private method to check, if a node value is None.</td> |
|
1265 </tr> |
|
1266 <tr> |
|
1267 <td><a href="#ReturnVisitor.__resultExists">__resultExists</a></td> |
|
1268 <td>Private method to check the existance of a return result.</td> |
|
1269 </tr> |
|
1270 <tr> |
|
1271 <td><a href="#ReturnVisitor.__visitAssignTarget">__visitAssignTarget</a></td> |
|
1272 <td>Private method to handle an assign target node.</td> |
|
1273 </tr> |
|
1274 <tr> |
|
1275 <td><a href="#ReturnVisitor.__visitLoop">__visitLoop</a></td> |
|
1276 <td>Private method to handle loop nodes.</td> |
|
1277 </tr> |
|
1278 <tr> |
|
1279 <td><a href="#ReturnVisitor.__visitWithStack">__visitWithStack</a></td> |
|
1280 <td>Private method to traverse a given function node using a stack.</td> |
|
1281 </tr> |
|
1282 <tr> |
|
1283 <td><a href="#ReturnVisitor.assigns">assigns</a></td> |
|
1284 <td>Public method to get the Assign nodes.</td> |
|
1285 </tr> |
|
1286 <tr> |
|
1287 <td><a href="#ReturnVisitor.refs">refs</a></td> |
|
1288 <td>Public method to get the References nodes.</td> |
|
1289 </tr> |
|
1290 <tr> |
|
1291 <td><a href="#ReturnVisitor.returns">returns</a></td> |
|
1292 <td>Public method to get the Return nodes.</td> |
|
1293 </tr> |
|
1294 <tr> |
|
1295 <td><a href="#ReturnVisitor.visit_Assign">visit_Assign</a></td> |
|
1296 <td>Public method to handle an assign node.</td> |
|
1297 </tr> |
|
1298 <tr> |
|
1299 <td><a href="#ReturnVisitor.visit_AsyncFor">visit_AsyncFor</a></td> |
|
1300 <td>Public method to handle an async for loop.</td> |
|
1301 </tr> |
|
1302 <tr> |
|
1303 <td><a href="#ReturnVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td> |
|
1304 <td>Public method to handle a function definition.</td> |
|
1305 </tr> |
|
1306 <tr> |
|
1307 <td><a href="#ReturnVisitor.visit_For">visit_For</a></td> |
|
1308 <td>Public method to handle a for loop.</td> |
|
1309 </tr> |
|
1310 <tr> |
|
1311 <td><a href="#ReturnVisitor.visit_FunctionDef">visit_FunctionDef</a></td> |
|
1312 <td>Public method to handle a function definition.</td> |
|
1313 </tr> |
|
1314 <tr> |
|
1315 <td><a href="#ReturnVisitor.visit_Name">visit_Name</a></td> |
|
1316 <td>Public method to handle a name node.</td> |
|
1317 </tr> |
|
1318 <tr> |
|
1319 <td><a href="#ReturnVisitor.visit_Return">visit_Return</a></td> |
|
1320 <td>Public method to handle a return node.</td> |
|
1321 </tr> |
|
1322 <tr> |
|
1323 <td><a href="#ReturnVisitor.visit_While">visit_While</a></td> |
|
1324 <td>Public method to handle a while loop.</td> |
|
1325 </tr> |
|
1326 </table> |
|
1327 <h3>Static Methods</h3> |
|
1328 |
|
1329 <table> |
|
1330 <tr><td>None</td></tr> |
|
1331 </table> |
|
1332 |
|
1333 <a NAME="ReturnVisitor.__init__" ID="ReturnVisitor.__init__"></a> |
|
1334 <h4>ReturnVisitor (Constructor)</h4> |
|
1335 <b>ReturnVisitor</b>(<i></i>) |
|
1336 |
|
1337 <p> |
|
1338 Constructor |
|
1339 </p> |
|
1340 <a NAME="ReturnVisitor.__checkFunction" ID="ReturnVisitor.__checkFunction"></a> |
|
1341 <h4>ReturnVisitor.__checkFunction</h4> |
|
1342 <b>__checkFunction</b>(<i>node</i>) |
|
1343 |
|
1344 <p> |
|
1345 Private method to check a function definition node. |
|
1346 </p> |
|
1347 <dl> |
|
1348 |
|
1349 <dt><i>node</i> (ast.AsyncFunctionDef or ast.FunctionDef)</dt> |
|
1350 <dd> |
|
1351 reference to the node to check |
|
1352 </dd> |
|
1353 </dl> |
|
1354 <a NAME="ReturnVisitor.__checkImplicitReturn" ID="ReturnVisitor.__checkImplicitReturn"></a> |
|
1355 <h4>ReturnVisitor.__checkImplicitReturn</h4> |
|
1356 <b>__checkImplicitReturn</b>(<i>node</i>) |
|
1357 |
|
1358 <p> |
|
1359 Private method to check for an implicit return statement. |
|
1360 </p> |
|
1361 <dl> |
|
1362 |
|
1363 <dt><i>node</i> (ast.AST)</dt> |
|
1364 <dd> |
|
1365 reference to the node to check |
|
1366 </dd> |
|
1367 </dl> |
|
1368 <a NAME="ReturnVisitor.__checkImplicitReturnValue" ID="ReturnVisitor.__checkImplicitReturnValue"></a> |
|
1369 <h4>ReturnVisitor.__checkImplicitReturnValue</h4> |
|
1370 <b>__checkImplicitReturnValue</b>(<i></i>) |
|
1371 |
|
1372 <p> |
|
1373 Private method to check for implicit return values. |
|
1374 </p> |
|
1375 <a NAME="ReturnVisitor.__checkUnnecessaryAssign" ID="ReturnVisitor.__checkUnnecessaryAssign"></a> |
|
1376 <h4>ReturnVisitor.__checkUnnecessaryAssign</h4> |
|
1377 <b>__checkUnnecessaryAssign</b>(<i>node</i>) |
|
1378 |
|
1379 <p> |
|
1380 Private method to check for an unnecessary assign statement. |
|
1381 </p> |
|
1382 <dl> |
|
1383 |
|
1384 <dt><i>node</i> (ast.AST)</dt> |
|
1385 <dd> |
|
1386 reference to the node to check |
|
1387 </dd> |
|
1388 </dl> |
|
1389 <a NAME="ReturnVisitor.__checkUnnecessaryReturnNone" ID="ReturnVisitor.__checkUnnecessaryReturnNone"></a> |
|
1390 <h4>ReturnVisitor.__checkUnnecessaryReturnNone</h4> |
|
1391 <b>__checkUnnecessaryReturnNone</b>(<i></i>) |
|
1392 |
|
1393 <p> |
|
1394 Private method to check for an unnecessary 'return None' statement. |
|
1395 </p> |
|
1396 <a NAME="ReturnVisitor.__hasRefsBeforeNextAssign" ID="ReturnVisitor.__hasRefsBeforeNextAssign"></a> |
|
1397 <h4>ReturnVisitor.__hasRefsBeforeNextAssign</h4> |
|
1398 <b>__hasRefsBeforeNextAssign</b>(<i>varname, returnLineno</i>) |
|
1399 |
|
1400 <p> |
|
1401 Private method to check for references before a following assign |
|
1402 statement. |
|
1403 </p> |
|
1404 <dl> |
|
1405 |
|
1406 <dt><i>varname</i> (str)</dt> |
|
1407 <dd> |
|
1408 variable name to check for |
|
1409 </dd> |
|
1410 <dt><i>returnLineno</i> (int)</dt> |
|
1411 <dd> |
|
1412 line number of the return statement |
|
1413 </dd> |
|
1414 </dl> |
|
1415 <dl> |
|
1416 <dt>Return:</dt> |
|
1417 <dd> |
|
1418 flag indicating the existence of references |
|
1419 </dd> |
|
1420 </dl> |
|
1421 <dl> |
|
1422 <dt>Return Type:</dt> |
|
1423 <dd> |
|
1424 bool |
|
1425 </dd> |
|
1426 </dl> |
|
1427 <a NAME="ReturnVisitor.__isFalse" ID="ReturnVisitor.__isFalse"></a> |
|
1428 <h4>ReturnVisitor.__isFalse</h4> |
|
1429 <b>__isFalse</b>(<i>node</i>) |
|
1430 |
|
1431 <p> |
|
1432 Private method to check, if a node value is False. |
|
1433 </p> |
|
1434 <dl> |
|
1435 |
|
1436 <dt><i>node</i> (ast.AST)</dt> |
|
1437 <dd> |
|
1438 reference to the node to check |
|
1439 </dd> |
|
1440 </dl> |
|
1441 <dl> |
|
1442 <dt>Return:</dt> |
|
1443 <dd> |
|
1444 flag indicating the node contains a False value |
|
1445 </dd> |
|
1446 </dl> |
|
1447 <dl> |
|
1448 <dt>Return Type:</dt> |
|
1449 <dd> |
|
1450 bool |
|
1451 </dd> |
|
1452 </dl> |
|
1453 <a NAME="ReturnVisitor.__isNone" ID="ReturnVisitor.__isNone"></a> |
|
1454 <h4>ReturnVisitor.__isNone</h4> |
|
1455 <b>__isNone</b>(<i>node</i>) |
|
1456 |
|
1457 <p> |
|
1458 Private method to check, if a node value is None. |
|
1459 </p> |
|
1460 <dl> |
|
1461 |
|
1462 <dt><i>node</i> (ast.AST)</dt> |
|
1463 <dd> |
|
1464 reference to the node to check |
|
1465 </dd> |
|
1466 </dl> |
|
1467 <dl> |
|
1468 <dt>Return:</dt> |
|
1469 <dd> |
|
1470 flag indicating the node contains a None value |
|
1471 </dd> |
|
1472 </dl> |
|
1473 <dl> |
|
1474 <dt>Return Type:</dt> |
|
1475 <dd> |
|
1476 bool |
|
1477 </dd> |
|
1478 </dl> |
|
1479 <a NAME="ReturnVisitor.__resultExists" ID="ReturnVisitor.__resultExists"></a> |
|
1480 <h4>ReturnVisitor.__resultExists</h4> |
|
1481 <b>__resultExists</b>(<i></i>) |
|
1482 |
|
1483 <p> |
|
1484 Private method to check the existance of a return result. |
|
1485 </p> |
|
1486 <dl> |
|
1487 <dt>Return:</dt> |
|
1488 <dd> |
|
1489 flag indicating the existence of a return result |
|
1490 </dd> |
|
1491 </dl> |
|
1492 <dl> |
|
1493 <dt>Return Type:</dt> |
|
1494 <dd> |
|
1495 bool |
|
1496 </dd> |
|
1497 </dl> |
|
1498 <a NAME="ReturnVisitor.__visitAssignTarget" ID="ReturnVisitor.__visitAssignTarget"></a> |
|
1499 <h4>ReturnVisitor.__visitAssignTarget</h4> |
|
1500 <b>__visitAssignTarget</b>(<i>node</i>) |
|
1501 |
|
1502 <p> |
|
1503 Private method to handle an assign target node. |
|
1504 </p> |
|
1505 <dl> |
|
1506 |
|
1507 <dt><i>node</i> (ast.AST)</dt> |
|
1508 <dd> |
|
1509 reference to the node to handle |
|
1510 </dd> |
|
1511 </dl> |
|
1512 <a NAME="ReturnVisitor.__visitLoop" ID="ReturnVisitor.__visitLoop"></a> |
|
1513 <h4>ReturnVisitor.__visitLoop</h4> |
|
1514 <b>__visitLoop</b>(<i>node</i>) |
|
1515 |
|
1516 <p> |
|
1517 Private method to handle loop nodes. |
|
1518 </p> |
|
1519 <dl> |
|
1520 |
|
1521 <dt><i>node</i> (ast.For, ast.AsyncFor or ast.While)</dt> |
|
1522 <dd> |
|
1523 reference to the loop node to handle |
|
1524 </dd> |
|
1525 </dl> |
|
1526 <a NAME="ReturnVisitor.__visitWithStack" ID="ReturnVisitor.__visitWithStack"></a> |
|
1527 <h4>ReturnVisitor.__visitWithStack</h4> |
|
1528 <b>__visitWithStack</b>(<i>node</i>) |
|
1529 |
|
1530 <p> |
|
1531 Private method to traverse a given function node using a stack. |
|
1532 </p> |
|
1533 <dl> |
|
1534 |
|
1535 <dt><i>node</i> (ast.FunctionDef or ast.AsyncFunctionDef)</dt> |
|
1536 <dd> |
|
1537 AST node to be traversed |
|
1538 </dd> |
|
1539 </dl> |
|
1540 <a NAME="ReturnVisitor.assigns" ID="ReturnVisitor.assigns"></a> |
|
1541 <h4>ReturnVisitor.assigns</h4> |
|
1542 <b>assigns</b>(<i></i>) |
|
1543 |
|
1544 <p> |
|
1545 Public method to get the Assign nodes. |
|
1546 </p> |
|
1547 <dl> |
|
1548 <dt>Return:</dt> |
|
1549 <dd> |
|
1550 dictionary containing the node name as key and line number |
|
1551 as value |
|
1552 </dd> |
|
1553 </dl> |
|
1554 <dl> |
|
1555 <dt>Return Type:</dt> |
|
1556 <dd> |
|
1557 dict |
|
1558 </dd> |
|
1559 </dl> |
|
1560 <a NAME="ReturnVisitor.refs" ID="ReturnVisitor.refs"></a> |
|
1561 <h4>ReturnVisitor.refs</h4> |
|
1562 <b>refs</b>(<i></i>) |
|
1563 |
|
1564 <p> |
|
1565 Public method to get the References nodes. |
|
1566 </p> |
|
1567 <dl> |
|
1568 <dt>Return:</dt> |
|
1569 <dd> |
|
1570 dictionary containing the node name as key and line number |
|
1571 as value |
|
1572 </dd> |
|
1573 </dl> |
|
1574 <dl> |
|
1575 <dt>Return Type:</dt> |
|
1576 <dd> |
|
1577 dict |
|
1578 </dd> |
|
1579 </dl> |
|
1580 <a NAME="ReturnVisitor.returns" ID="ReturnVisitor.returns"></a> |
|
1581 <h4>ReturnVisitor.returns</h4> |
|
1582 <b>returns</b>(<i></i>) |
|
1583 |
|
1584 <p> |
|
1585 Public method to get the Return nodes. |
|
1586 </p> |
|
1587 <dl> |
|
1588 <dt>Return:</dt> |
|
1589 <dd> |
|
1590 dictionary containing the node name as key and line number |
|
1591 as value |
|
1592 </dd> |
|
1593 </dl> |
|
1594 <dl> |
|
1595 <dt>Return Type:</dt> |
|
1596 <dd> |
|
1597 dict |
|
1598 </dd> |
|
1599 </dl> |
|
1600 <a NAME="ReturnVisitor.visit_Assign" ID="ReturnVisitor.visit_Assign"></a> |
|
1601 <h4>ReturnVisitor.visit_Assign</h4> |
|
1602 <b>visit_Assign</b>(<i>node</i>) |
|
1603 |
|
1604 <p> |
|
1605 Public method to handle an assign node. |
|
1606 </p> |
|
1607 <dl> |
|
1608 |
|
1609 <dt><i>node</i> (ast.Assign)</dt> |
|
1610 <dd> |
|
1611 reference to the node to handle |
|
1612 </dd> |
|
1613 </dl> |
|
1614 <a NAME="ReturnVisitor.visit_AsyncFor" ID="ReturnVisitor.visit_AsyncFor"></a> |
|
1615 <h4>ReturnVisitor.visit_AsyncFor</h4> |
|
1616 <b>visit_AsyncFor</b>(<i>node</i>) |
|
1617 |
|
1618 <p> |
|
1619 Public method to handle an async for loop. |
|
1620 </p> |
|
1621 <dl> |
|
1622 |
|
1623 <dt><i>node</i> (ast.AsyncFor)</dt> |
|
1624 <dd> |
|
1625 reference to the async for node to handle |
|
1626 </dd> |
|
1627 </dl> |
|
1628 <a NAME="ReturnVisitor.visit_AsyncFunctionDef" ID="ReturnVisitor.visit_AsyncFunctionDef"></a> |
|
1629 <h4>ReturnVisitor.visit_AsyncFunctionDef</h4> |
|
1630 <b>visit_AsyncFunctionDef</b>(<i>node</i>) |
|
1631 |
|
1632 <p> |
|
1633 Public method to handle a function definition. |
|
1634 </p> |
|
1635 <dl> |
|
1636 |
|
1637 <dt><i>node</i> (ast.AsyncFunctionDef)</dt> |
|
1638 <dd> |
|
1639 reference to the node to handle |
|
1640 </dd> |
|
1641 </dl> |
|
1642 <a NAME="ReturnVisitor.visit_For" ID="ReturnVisitor.visit_For"></a> |
|
1643 <h4>ReturnVisitor.visit_For</h4> |
|
1644 <b>visit_For</b>(<i>node</i>) |
|
1645 |
|
1646 <p> |
|
1647 Public method to handle a for loop. |
|
1648 </p> |
|
1649 <dl> |
|
1650 |
|
1651 <dt><i>node</i> (ast.For)</dt> |
|
1652 <dd> |
|
1653 reference to the for node to handle |
|
1654 </dd> |
|
1655 </dl> |
|
1656 <a NAME="ReturnVisitor.visit_FunctionDef" ID="ReturnVisitor.visit_FunctionDef"></a> |
|
1657 <h4>ReturnVisitor.visit_FunctionDef</h4> |
|
1658 <b>visit_FunctionDef</b>(<i>node</i>) |
|
1659 |
|
1660 <p> |
|
1661 Public method to handle a function definition. |
|
1662 </p> |
|
1663 <dl> |
|
1664 |
|
1665 <dt><i>node</i> (ast.FunctionDef)</dt> |
|
1666 <dd> |
|
1667 reference to the node to handle |
|
1668 </dd> |
|
1669 </dl> |
|
1670 <a NAME="ReturnVisitor.visit_Name" ID="ReturnVisitor.visit_Name"></a> |
|
1671 <h4>ReturnVisitor.visit_Name</h4> |
|
1672 <b>visit_Name</b>(<i>node</i>) |
|
1673 |
|
1674 <p> |
|
1675 Public method to handle a name node. |
|
1676 </p> |
|
1677 <dl> |
|
1678 |
|
1679 <dt><i>node</i> (ast.Name)</dt> |
|
1680 <dd> |
|
1681 reference to the node to handle |
|
1682 </dd> |
|
1683 </dl> |
|
1684 <a NAME="ReturnVisitor.visit_Return" ID="ReturnVisitor.visit_Return"></a> |
|
1685 <h4>ReturnVisitor.visit_Return</h4> |
|
1686 <b>visit_Return</b>(<i>node</i>) |
|
1687 |
|
1688 <p> |
|
1689 Public method to handle a return node. |
|
1690 </p> |
|
1691 <dl> |
|
1692 |
|
1693 <dt><i>node</i> (ast.Return)</dt> |
|
1694 <dd> |
|
1695 reference to the node to handle |
|
1696 </dd> |
|
1697 </dl> |
|
1698 <a NAME="ReturnVisitor.visit_While" ID="ReturnVisitor.visit_While"></a> |
|
1699 <h4>ReturnVisitor.visit_While</h4> |
|
1700 <b>visit_While</b>(<i>node</i>) |
|
1701 |
|
1702 <p> |
|
1703 Public method to handle a while loop. |
|
1704 </p> |
|
1705 <dl> |
|
1706 |
|
1707 <dt><i>node</i> (ast.While)</dt> |
|
1708 <dd> |
|
1709 reference to the while node to handle |
|
1710 </dd> |
|
1711 </dl> |
|
1712 <div align="right"><a href="#top">Up</a></div> |
|
1713 <hr /> |
|
1714 <hr /> |
|
1715 <a NAME="SysVersionVisitor" ID="SysVersionVisitor"></a> |
|
1716 <h2>SysVersionVisitor</h2> |
|
1717 |
|
1718 <p> |
|
1719 Class implementing a node visitor to check the use of sys.version and |
|
1720 sys.version_info. |
|
1721 </p> |
|
1722 <p> |
|
1723 Note: This class is modelled after flake8-2020 checker. |
|
1724 </p> |
|
1725 <h3>Derived from</h3> |
|
1726 ast.NodeVisitor |
|
1727 <h3>Class Attributes</h3> |
|
1728 |
|
1729 <table> |
|
1730 <tr><td>None</td></tr> |
|
1731 </table> |
|
1732 <h3>Class Methods</h3> |
|
1733 |
|
1734 <table> |
|
1735 <tr><td>None</td></tr> |
|
1736 </table> |
|
1737 <h3>Methods</h3> |
|
1738 |
|
1739 <table> |
|
1740 |
|
1741 <tr> |
|
1742 <td><a href="#SysVersionVisitor.__init__">SysVersionVisitor</a></td> |
|
1743 <td>Constructor</td> |
|
1744 </tr> |
|
1745 <tr> |
|
1746 <td><a href="#SysVersionVisitor.__isSys">__isSys</a></td> |
|
1747 <td>Private method to check for a reference to sys attribute.</td> |
|
1748 </tr> |
|
1749 <tr> |
|
1750 <td><a href="#SysVersionVisitor.__isSysVersionUpperSlice">__isSysVersionUpperSlice</a></td> |
|
1751 <td>Private method to check the upper slice of sys.version.</td> |
|
1752 </tr> |
|
1753 <tr> |
|
1754 <td><a href="#SysVersionVisitor.visit_Attribute">visit_Attribute</a></td> |
|
1755 <td>Public method to handle an attribute.</td> |
|
1756 </tr> |
|
1757 <tr> |
|
1758 <td><a href="#SysVersionVisitor.visit_Compare">visit_Compare</a></td> |
|
1759 <td>Public method to handle a comparison.</td> |
|
1760 </tr> |
|
1761 <tr> |
|
1762 <td><a href="#SysVersionVisitor.visit_ImportFrom">visit_ImportFrom</a></td> |
|
1763 <td>Public method to handle a from ...</td> |
|
1764 </tr> |
|
1765 <tr> |
|
1766 <td><a href="#SysVersionVisitor.visit_Name">visit_Name</a></td> |
|
1767 <td>Public method to handle an name.</td> |
|
1768 </tr> |
|
1769 <tr> |
|
1770 <td><a href="#SysVersionVisitor.visit_Subscript">visit_Subscript</a></td> |
|
1771 <td>Public method to handle a subscript.</td> |
|
1772 </tr> |
|
1773 </table> |
|
1774 <h3>Static Methods</h3> |
|
1775 |
|
1776 <table> |
|
1777 <tr><td>None</td></tr> |
|
1778 </table> |
|
1779 |
|
1780 <a NAME="SysVersionVisitor.__init__" ID="SysVersionVisitor.__init__"></a> |
|
1781 <h4>SysVersionVisitor (Constructor)</h4> |
|
1782 <b>SysVersionVisitor</b>(<i></i>) |
|
1783 |
|
1784 <p> |
|
1785 Constructor |
|
1786 </p> |
|
1787 <a NAME="SysVersionVisitor.__isSys" ID="SysVersionVisitor.__isSys"></a> |
|
1788 <h4>SysVersionVisitor.__isSys</h4> |
|
1789 <b>__isSys</b>(<i>attr, node</i>) |
|
1790 |
|
1791 <p> |
|
1792 Private method to check for a reference to sys attribute. |
|
1793 </p> |
|
1794 <dl> |
|
1795 |
|
1796 <dt><i>attr</i> (str)</dt> |
|
1797 <dd> |
|
1798 attribute name |
|
1799 </dd> |
|
1800 <dt><i>node</i> (ast.Node)</dt> |
|
1801 <dd> |
|
1802 reference to the node to be checked |
|
1803 </dd> |
|
1804 </dl> |
|
1805 <dl> |
|
1806 <dt>Return:</dt> |
|
1807 <dd> |
|
1808 flag indicating a match |
|
1809 </dd> |
|
1810 </dl> |
|
1811 <dl> |
|
1812 <dt>Return Type:</dt> |
|
1813 <dd> |
|
1814 bool |
|
1815 </dd> |
|
1816 </dl> |
|
1817 <a NAME="SysVersionVisitor.__isSysVersionUpperSlice" ID="SysVersionVisitor.__isSysVersionUpperSlice"></a> |
|
1818 <h4>SysVersionVisitor.__isSysVersionUpperSlice</h4> |
|
1819 <b>__isSysVersionUpperSlice</b>(<i>node, n</i>) |
|
1820 |
|
1821 <p> |
|
1822 Private method to check the upper slice of sys.version. |
|
1823 </p> |
|
1824 <dl> |
|
1825 |
|
1826 <dt><i>node</i> (ast.Node)</dt> |
|
1827 <dd> |
|
1828 reference to the node to be checked |
|
1829 </dd> |
|
1830 <dt><i>n</i> (int)</dt> |
|
1831 <dd> |
|
1832 slice value to check against |
|
1833 </dd> |
|
1834 </dl> |
|
1835 <dl> |
|
1836 <dt>Return:</dt> |
|
1837 <dd> |
|
1838 flag indicating a match |
|
1839 </dd> |
|
1840 </dl> |
|
1841 <dl> |
|
1842 <dt>Return Type:</dt> |
|
1843 <dd> |
|
1844 bool |
|
1845 </dd> |
|
1846 </dl> |
|
1847 <a NAME="SysVersionVisitor.visit_Attribute" ID="SysVersionVisitor.visit_Attribute"></a> |
|
1848 <h4>SysVersionVisitor.visit_Attribute</h4> |
|
1849 <b>visit_Attribute</b>(<i>node</i>) |
|
1850 |
|
1851 <p> |
|
1852 Public method to handle an attribute. |
|
1853 </p> |
|
1854 <dl> |
|
1855 |
|
1856 <dt><i>node</i> (ast.Attribute)</dt> |
|
1857 <dd> |
|
1858 reference to the node to be processed |
|
1859 </dd> |
|
1860 </dl> |
|
1861 <a NAME="SysVersionVisitor.visit_Compare" ID="SysVersionVisitor.visit_Compare"></a> |
|
1862 <h4>SysVersionVisitor.visit_Compare</h4> |
|
1863 <b>visit_Compare</b>(<i>node</i>) |
|
1864 |
|
1865 <p> |
|
1866 Public method to handle a comparison. |
|
1867 </p> |
|
1868 <dl> |
|
1869 |
|
1870 <dt><i>node</i> (ast.Compare)</dt> |
|
1871 <dd> |
|
1872 reference to the node to be processed |
|
1873 </dd> |
|
1874 </dl> |
|
1875 <a NAME="SysVersionVisitor.visit_ImportFrom" ID="SysVersionVisitor.visit_ImportFrom"></a> |
|
1876 <h4>SysVersionVisitor.visit_ImportFrom</h4> |
|
1877 <b>visit_ImportFrom</b>(<i>node</i>) |
|
1878 |
|
1879 <p> |
|
1880 Public method to handle a from ... import ... statement. |
|
1881 </p> |
|
1882 <dl> |
|
1883 |
|
1884 <dt><i>node</i> (ast.ImportFrom)</dt> |
|
1885 <dd> |
|
1886 reference to the node to be processed |
|
1887 </dd> |
|
1888 </dl> |
|
1889 <a NAME="SysVersionVisitor.visit_Name" ID="SysVersionVisitor.visit_Name"></a> |
|
1890 <h4>SysVersionVisitor.visit_Name</h4> |
|
1891 <b>visit_Name</b>(<i>node</i>) |
|
1892 |
|
1893 <p> |
|
1894 Public method to handle an name. |
|
1895 </p> |
|
1896 <dl> |
|
1897 |
|
1898 <dt><i>node</i> (ast.Name)</dt> |
|
1899 <dd> |
|
1900 reference to the node to be processed |
|
1901 </dd> |
|
1902 </dl> |
|
1903 <a NAME="SysVersionVisitor.visit_Subscript" ID="SysVersionVisitor.visit_Subscript"></a> |
|
1904 <h4>SysVersionVisitor.visit_Subscript</h4> |
|
1905 <b>visit_Subscript</b>(<i>node</i>) |
|
1906 |
|
1907 <p> |
|
1908 Public method to handle a subscript. |
|
1909 </p> |
|
1910 <dl> |
|
1911 |
|
1912 <dt><i>node</i> (ast.Subscript)</dt> |
|
1913 <dd> |
|
1914 reference to the node to be processed |
|
1915 </dd> |
|
1916 </dl> |
|
1917 <div align="right"><a href="#top">Up</a></div> |
|
1918 <hr /> |
|
1919 <hr /> |
|
1920 <a NAME="TextVisitor" ID="TextVisitor"></a> |
|
1921 <h2>TextVisitor</h2> |
|
1922 |
|
1923 <p> |
|
1924 Class implementing a node visitor for bytes and str instances. |
|
1925 </p> |
|
1926 <p> |
|
1927 It tries to detect docstrings as string of the first expression of each |
|
1928 module, class or function. |
|
1929 </p> |
|
1930 <h3>Derived from</h3> |
|
1931 ast.NodeVisitor |
|
1932 <h3>Class Attributes</h3> |
|
1933 |
|
1934 <table> |
|
1935 <tr><td>None</td></tr> |
|
1936 </table> |
|
1937 <h3>Class Methods</h3> |
|
1938 |
|
1939 <table> |
|
1940 <tr><td>None</td></tr> |
|
1941 </table> |
|
1942 <h3>Methods</h3> |
|
1943 |
|
1944 <table> |
|
1945 |
|
1946 <tr> |
|
1947 <td><a href="#TextVisitor.__init__">TextVisitor</a></td> |
|
1948 <td>Constructor</td> |
|
1949 </tr> |
|
1950 <tr> |
|
1951 <td><a href="#TextVisitor.__addNode">__addNode</a></td> |
|
1952 <td>Private method to add a node to our list of nodes.</td> |
|
1953 </tr> |
|
1954 <tr> |
|
1955 <td><a href="#TextVisitor.__visitBody">__visitBody</a></td> |
|
1956 <td>Private method to traverse the body of the node manually.</td> |
|
1957 </tr> |
|
1958 <tr> |
|
1959 <td><a href="#TextVisitor.__visitDefinition">__visitDefinition</a></td> |
|
1960 <td>Private method handling class and function definitions.</td> |
|
1961 </tr> |
|
1962 <tr> |
|
1963 <td><a href="#TextVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td> |
|
1964 <td>Public method to handle an asynchronous function definition.</td> |
|
1965 </tr> |
|
1966 <tr> |
|
1967 <td><a href="#TextVisitor.visit_Bytes">visit_Bytes</a></td> |
|
1968 <td>Public method to record a bytes node.</td> |
|
1969 </tr> |
|
1970 <tr> |
|
1971 <td><a href="#TextVisitor.visit_Call">visit_Call</a></td> |
|
1972 <td>Public method to handle a function call.</td> |
|
1973 </tr> |
|
1974 <tr> |
|
1975 <td><a href="#TextVisitor.visit_ClassDef">visit_ClassDef</a></td> |
|
1976 <td>Public method to handle a class definition.</td> |
|
1977 </tr> |
|
1978 <tr> |
|
1979 <td><a href="#TextVisitor.visit_Constant">visit_Constant</a></td> |
|
1980 <td>Public method to handle constant nodes.</td> |
|
1981 </tr> |
|
1982 <tr> |
|
1983 <td><a href="#TextVisitor.visit_FunctionDef">visit_FunctionDef</a></td> |
|
1984 <td>Public method to handle a function definition.</td> |
|
1985 </tr> |
|
1986 <tr> |
|
1987 <td><a href="#TextVisitor.visit_Module">visit_Module</a></td> |
|
1988 <td>Public method to handle a module.</td> |
|
1989 </tr> |
|
1990 <tr> |
|
1991 <td><a href="#TextVisitor.visit_Str">visit_Str</a></td> |
|
1992 <td>Public method to record a string node.</td> |
|
1993 </tr> |
|
1994 </table> |
|
1995 <h3>Static Methods</h3> |
|
1996 |
|
1997 <table> |
|
1998 <tr><td>None</td></tr> |
|
1999 </table> |
|
2000 |
|
2001 <a NAME="TextVisitor.__init__" ID="TextVisitor.__init__"></a> |
|
2002 <h4>TextVisitor (Constructor)</h4> |
|
2003 <b>TextVisitor</b>(<i></i>) |
|
2004 |
|
2005 <p> |
|
2006 Constructor |
|
2007 </p> |
|
2008 <a NAME="TextVisitor.__addNode" ID="TextVisitor.__addNode"></a> |
|
2009 <h4>TextVisitor.__addNode</h4> |
|
2010 <b>__addNode</b>(<i>node</i>) |
|
2011 |
|
2012 <p> |
|
2013 Private method to add a node to our list of nodes. |
|
2014 </p> |
|
2015 <dl> |
|
2016 |
|
2017 <dt><i>node</i> (ast.AST)</dt> |
|
2018 <dd> |
|
2019 reference to the node to add |
|
2020 </dd> |
|
2021 </dl> |
|
2022 <a NAME="TextVisitor.__visitBody" ID="TextVisitor.__visitBody"></a> |
|
2023 <h4>TextVisitor.__visitBody</h4> |
|
2024 <b>__visitBody</b>(<i>node</i>) |
|
2025 |
|
2026 <p> |
|
2027 Private method to traverse the body of the node manually. |
|
2028 </p> |
|
2029 <p> |
|
2030 If the first node is an expression which contains a string or bytes it |
|
2031 marks that as a docstring. |
|
2032 </p> |
|
2033 <dl> |
|
2034 |
|
2035 <dt><i>node</i> (ast.AST)</dt> |
|
2036 <dd> |
|
2037 reference to the node to traverse |
|
2038 </dd> |
|
2039 </dl> |
|
2040 <a NAME="TextVisitor.__visitDefinition" ID="TextVisitor.__visitDefinition"></a> |
|
2041 <h4>TextVisitor.__visitDefinition</h4> |
|
2042 <b>__visitDefinition</b>(<i>node</i>) |
|
2043 |
|
2044 <p> |
|
2045 Private method handling class and function definitions. |
|
2046 </p> |
|
2047 <dl> |
|
2048 |
|
2049 <dt><i>node</i> (ast.FunctionDef, ast.AsyncFunctionDef or ast.ClassDef)</dt> |
|
2050 <dd> |
|
2051 reference to the node to handle |
|
2052 </dd> |
|
2053 </dl> |
|
2054 <a NAME="TextVisitor.visit_AsyncFunctionDef" ID="TextVisitor.visit_AsyncFunctionDef"></a> |
|
2055 <h4>TextVisitor.visit_AsyncFunctionDef</h4> |
|
2056 <b>visit_AsyncFunctionDef</b>(<i>node</i>) |
|
2057 |
|
2058 <p> |
|
2059 Public method to handle an asynchronous function definition. |
|
2060 </p> |
|
2061 <dl> |
|
2062 |
|
2063 <dt><i>node</i> (ast.AsyncFunctionDef)</dt> |
|
2064 <dd> |
|
2065 reference to the node to handle |
|
2066 </dd> |
|
2067 </dl> |
|
2068 <a NAME="TextVisitor.visit_Bytes" ID="TextVisitor.visit_Bytes"></a> |
|
2069 <h4>TextVisitor.visit_Bytes</h4> |
|
2070 <b>visit_Bytes</b>(<i>node</i>) |
|
2071 |
|
2072 <p> |
|
2073 Public method to record a bytes node. |
|
2074 </p> |
|
2075 <dl> |
|
2076 |
|
2077 <dt><i>node</i> (ast.Bytes)</dt> |
|
2078 <dd> |
|
2079 reference to the bytes node |
|
2080 </dd> |
|
2081 </dl> |
|
2082 <a NAME="TextVisitor.visit_Call" ID="TextVisitor.visit_Call"></a> |
|
2083 <h4>TextVisitor.visit_Call</h4> |
|
2084 <b>visit_Call</b>(<i>node</i>) |
|
2085 |
|
2086 <p> |
|
2087 Public method to handle a function call. |
|
2088 </p> |
|
2089 <dl> |
|
2090 |
|
2091 <dt><i>node</i> (ast.Call)</dt> |
|
2092 <dd> |
|
2093 reference to the node to handle |
|
2094 </dd> |
|
2095 </dl> |
|
2096 <a NAME="TextVisitor.visit_ClassDef" ID="TextVisitor.visit_ClassDef"></a> |
|
2097 <h4>TextVisitor.visit_ClassDef</h4> |
|
2098 <b>visit_ClassDef</b>(<i>node</i>) |
|
2099 |
|
2100 <p> |
|
2101 Public method to handle a class definition. |
|
2102 </p> |
|
2103 <dl> |
|
2104 |
|
2105 <dt><i>node</i> (ast.ClassDef)</dt> |
|
2106 <dd> |
|
2107 reference to the node to handle |
|
2108 </dd> |
|
2109 </dl> |
|
2110 <a NAME="TextVisitor.visit_Constant" ID="TextVisitor.visit_Constant"></a> |
|
2111 <h4>TextVisitor.visit_Constant</h4> |
|
2112 <b>visit_Constant</b>(<i>node</i>) |
|
2113 |
|
2114 <p> |
|
2115 Public method to handle constant nodes. |
|
2116 </p> |
|
2117 <dl> |
|
2118 |
|
2119 <dt><i>node</i> (ast.Constant)</dt> |
|
2120 <dd> |
|
2121 reference to the bytes node |
|
2122 </dd> |
|
2123 </dl> |
|
2124 <a NAME="TextVisitor.visit_FunctionDef" ID="TextVisitor.visit_FunctionDef"></a> |
|
2125 <h4>TextVisitor.visit_FunctionDef</h4> |
|
2126 <b>visit_FunctionDef</b>(<i>node</i>) |
|
2127 |
|
2128 <p> |
|
2129 Public method to handle a function definition. |
|
2130 </p> |
|
2131 <dl> |
|
2132 |
|
2133 <dt><i>node</i> (ast.FunctionDef)</dt> |
|
2134 <dd> |
|
2135 reference to the node to handle |
|
2136 </dd> |
|
2137 </dl> |
|
2138 <a NAME="TextVisitor.visit_Module" ID="TextVisitor.visit_Module"></a> |
|
2139 <h4>TextVisitor.visit_Module</h4> |
|
2140 <b>visit_Module</b>(<i>node</i>) |
|
2141 |
|
2142 <p> |
|
2143 Public method to handle a module. |
|
2144 </p> |
|
2145 <dl> |
|
2146 |
|
2147 <dt><i>node</i> (ast.Module)</dt> |
|
2148 <dd> |
|
2149 reference to the node to handle |
|
2150 </dd> |
|
2151 </dl> |
|
2152 <a NAME="TextVisitor.visit_Str" ID="TextVisitor.visit_Str"></a> |
|
2153 <h4>TextVisitor.visit_Str</h4> |
|
2154 <b>visit_Str</b>(<i>node</i>) |
|
2155 |
|
2156 <p> |
|
2157 Public method to record a string node. |
|
2158 </p> |
|
2159 <dl> |
|
2160 |
|
2161 <dt><i>node</i> (ast.Str)</dt> |
|
2162 <dd> |
|
2163 reference to the string node |
|
2164 </dd> |
|
2165 </dl> |
|
2166 <div align="right"><a href="#top">Up</a></div> |
|
2167 <hr /> |
|
2168 <hr /> |
|
2169 <a NAME="composeCallPath" ID="composeCallPath"></a> |
|
2170 <h2>composeCallPath</h2> |
|
2171 <b>composeCallPath</b>(<i>node</i>) |
|
2172 |
|
2173 <p> |
|
2174 Generator function to assemble the call path of a given node. |
|
2175 </p> |
|
2176 <dl> |
|
2177 |
|
2178 <dt><i>node</i> (ast.Node)</dt> |
|
2179 <dd> |
|
2180 node to assemble call path for |
|
2181 </dd> |
|
2182 </dl> |
|
2183 <dl> |
|
2184 <dt>Yield:</dt> |
|
2185 <dd> |
|
2186 call path components |
|
2187 </dd> |
|
2188 </dl> |
|
2189 <dl> |
|
2190 <dt>Yield Type:</dt> |
|
2191 <dd> |
|
2192 str |
|
2193 </dd> |
|
2194 </dl> |
|
2195 <div align="right"><a href="#top">Up</a></div> |
|
2196 <hr /> |
|
2197 </body></html> |