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