|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric6.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>eric6.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>Returns:</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>Returns:</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>Returns:</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>Returns:</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>Returns:</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>Returns:</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 object |
|
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.__generateTree">__generateTree</a></td> |
|
774 <td>Private method to generate an AST for our source.</td> |
|
775 </tr> |
|
776 <tr> |
|
777 <td><a href="#MiscellaneousChecker.__getCoding">__getCoding</a></td> |
|
778 <td>Private method to get the defined coding of the source.</td> |
|
779 </tr> |
|
780 <tr> |
|
781 <td><a href="#MiscellaneousChecker.__getFields">__getFields</a></td> |
|
782 <td>Private method to extract the format field information.</td> |
|
783 </tr> |
|
784 <tr> |
|
785 <td><a href="#MiscellaneousChecker.__ignoreCode">__ignoreCode</a></td> |
|
786 <td>Private method to check if the message code should be ignored.</td> |
|
787 </tr> |
|
788 <tr> |
|
789 <td><a href="#MiscellaneousChecker.__reportInvalidSyntax">__reportInvalidSyntax</a></td> |
|
790 <td>Private method to report a syntax error.</td> |
|
791 </tr> |
|
792 <tr> |
|
793 <td><a href="#MiscellaneousChecker.run">run</a></td> |
|
794 <td>Public method to check the given source against miscellaneous conditions.</td> |
|
795 </tr> |
|
796 </table> |
|
797 <h3>Static Methods</h3> |
|
798 |
|
799 <table> |
|
800 <tr><td>None</td></tr> |
|
801 </table> |
|
802 |
|
803 <a NAME="MiscellaneousChecker.__init__" ID="MiscellaneousChecker.__init__"></a> |
|
804 <h4>MiscellaneousChecker (Constructor)</h4> |
|
805 <b>MiscellaneousChecker</b>(<i>source, filename, select, ignore, expected, repeat, args</i>) |
|
806 |
|
807 <p> |
|
808 Constructor |
|
809 </p> |
|
810 <dl> |
|
811 |
|
812 <dt><i>source</i> (list of str)</dt> |
|
813 <dd> |
|
814 source code to be checked |
|
815 </dd> |
|
816 <dt><i>filename</i> (str)</dt> |
|
817 <dd> |
|
818 name of the source file |
|
819 </dd> |
|
820 <dt><i>select</i> (list of str)</dt> |
|
821 <dd> |
|
822 list of selected codes |
|
823 </dd> |
|
824 <dt><i>ignore</i> (list of str)</dt> |
|
825 <dd> |
|
826 list of codes to be ignored |
|
827 </dd> |
|
828 <dt><i>expected</i> (list of str)</dt> |
|
829 <dd> |
|
830 list of expected codes |
|
831 </dd> |
|
832 <dt><i>repeat</i> (bool)</dt> |
|
833 <dd> |
|
834 flag indicating to report each occurrence of a code |
|
835 </dd> |
|
836 <dt><i>args</i> (dict)</dt> |
|
837 <dd> |
|
838 dictionary of arguments for the miscellaneous checks |
|
839 </dd> |
|
840 </dl> |
|
841 <a NAME="MiscellaneousChecker.__checkBugBear" ID="MiscellaneousChecker.__checkBugBear"></a> |
|
842 <h4>MiscellaneousChecker.__checkBugBear</h4> |
|
843 <b>__checkBugBear</b>(<i></i>) |
|
844 |
|
845 <p> |
|
846 Private method for bugbear checks. |
|
847 </p> |
|
848 <a NAME="MiscellaneousChecker.__checkBuiltins" ID="MiscellaneousChecker.__checkBuiltins"></a> |
|
849 <h4>MiscellaneousChecker.__checkBuiltins</h4> |
|
850 <b>__checkBuiltins</b>(<i></i>) |
|
851 |
|
852 <p> |
|
853 Private method to check, if built-ins are shadowed. |
|
854 </p> |
|
855 <a NAME="MiscellaneousChecker.__checkCoding" ID="MiscellaneousChecker.__checkCoding"></a> |
|
856 <h4>MiscellaneousChecker.__checkCoding</h4> |
|
857 <b>__checkCoding</b>(<i></i>) |
|
858 |
|
859 <p> |
|
860 Private method to check the presence of a coding line and valid |
|
861 encodings. |
|
862 </p> |
|
863 <a NAME="MiscellaneousChecker.__checkCommentedCode" ID="MiscellaneousChecker.__checkCommentedCode"></a> |
|
864 <h4>MiscellaneousChecker.__checkCommentedCode</h4> |
|
865 <b>__checkCommentedCode</b>(<i></i>) |
|
866 |
|
867 <p> |
|
868 Private method to check for commented code. |
|
869 </p> |
|
870 <a NAME="MiscellaneousChecker.__checkComprehensions" ID="MiscellaneousChecker.__checkComprehensions"></a> |
|
871 <h4>MiscellaneousChecker.__checkComprehensions</h4> |
|
872 <b>__checkComprehensions</b>(<i></i>) |
|
873 |
|
874 <p> |
|
875 Private method to check some comprehension related things. |
|
876 </p> |
|
877 <a NAME="MiscellaneousChecker.__checkCopyright" ID="MiscellaneousChecker.__checkCopyright"></a> |
|
878 <h4>MiscellaneousChecker.__checkCopyright</h4> |
|
879 <b>__checkCopyright</b>(<i></i>) |
|
880 |
|
881 <p> |
|
882 Private method to check the presence of a copyright statement. |
|
883 </p> |
|
884 <a NAME="MiscellaneousChecker.__checkDateTime" ID="MiscellaneousChecker.__checkDateTime"></a> |
|
885 <h4>MiscellaneousChecker.__checkDateTime</h4> |
|
886 <b>__checkDateTime</b>(<i></i>) |
|
887 |
|
888 <p> |
|
889 Private method to check use of naive datetime functions. |
|
890 </p> |
|
891 <a NAME="MiscellaneousChecker.__checkDictWithSortedKeys" ID="MiscellaneousChecker.__checkDictWithSortedKeys"></a> |
|
892 <h4>MiscellaneousChecker.__checkDictWithSortedKeys</h4> |
|
893 <b>__checkDictWithSortedKeys</b>(<i></i>) |
|
894 |
|
895 <p> |
|
896 Private method to check, if dictionary keys appear in sorted order. |
|
897 </p> |
|
898 <a NAME="MiscellaneousChecker.__checkFormatString" ID="MiscellaneousChecker.__checkFormatString"></a> |
|
899 <h4>MiscellaneousChecker.__checkFormatString</h4> |
|
900 <b>__checkFormatString</b>(<i></i>) |
|
901 |
|
902 <p> |
|
903 Private method to check string format strings. |
|
904 </p> |
|
905 <a NAME="MiscellaneousChecker.__checkFuture" ID="MiscellaneousChecker.__checkFuture"></a> |
|
906 <h4>MiscellaneousChecker.__checkFuture</h4> |
|
907 <b>__checkFuture</b>(<i></i>) |
|
908 |
|
909 <p> |
|
910 Private method to check the __future__ imports. |
|
911 </p> |
|
912 <a NAME="MiscellaneousChecker.__checkGettext" ID="MiscellaneousChecker.__checkGettext"></a> |
|
913 <h4>MiscellaneousChecker.__checkGettext</h4> |
|
914 <b>__checkGettext</b>(<i></i>) |
|
915 |
|
916 <p> |
|
917 Private method to check the 'gettext' import statement. |
|
918 </p> |
|
919 <a NAME="MiscellaneousChecker.__checkLineContinuation" ID="MiscellaneousChecker.__checkLineContinuation"></a> |
|
920 <h4>MiscellaneousChecker.__checkLineContinuation</h4> |
|
921 <b>__checkLineContinuation</b>(<i></i>) |
|
922 |
|
923 <p> |
|
924 Private method to check line continuation using backslash. |
|
925 </p> |
|
926 <a NAME="MiscellaneousChecker.__checkLogging" ID="MiscellaneousChecker.__checkLogging"></a> |
|
927 <h4>MiscellaneousChecker.__checkLogging</h4> |
|
928 <b>__checkLogging</b>(<i></i>) |
|
929 |
|
930 <p> |
|
931 Private method to check logging statements. |
|
932 </p> |
|
933 <a NAME="MiscellaneousChecker.__checkMutableDefault" ID="MiscellaneousChecker.__checkMutableDefault"></a> |
|
934 <h4>MiscellaneousChecker.__checkMutableDefault</h4> |
|
935 <b>__checkMutableDefault</b>(<i></i>) |
|
936 |
|
937 <p> |
|
938 Private method to check for use of mutable types as default arguments. |
|
939 </p> |
|
940 <a NAME="MiscellaneousChecker.__checkPep3101" ID="MiscellaneousChecker.__checkPep3101"></a> |
|
941 <h4>MiscellaneousChecker.__checkPep3101</h4> |
|
942 <b>__checkPep3101</b>(<i></i>) |
|
943 |
|
944 <p> |
|
945 Private method to check for old style string formatting. |
|
946 </p> |
|
947 <a NAME="MiscellaneousChecker.__checkPrintStatements" ID="MiscellaneousChecker.__checkPrintStatements"></a> |
|
948 <h4>MiscellaneousChecker.__checkPrintStatements</h4> |
|
949 <b>__checkPrintStatements</b>(<i></i>) |
|
950 |
|
951 <p> |
|
952 Private method to check for print statements. |
|
953 </p> |
|
954 <a NAME="MiscellaneousChecker.__checkReturn" ID="MiscellaneousChecker.__checkReturn"></a> |
|
955 <h4>MiscellaneousChecker.__checkReturn</h4> |
|
956 <b>__checkReturn</b>(<i></i>) |
|
957 |
|
958 <p> |
|
959 Private method to check return statements. |
|
960 </p> |
|
961 <a NAME="MiscellaneousChecker.__checkSysVersion" ID="MiscellaneousChecker.__checkSysVersion"></a> |
|
962 <h4>MiscellaneousChecker.__checkSysVersion</h4> |
|
963 <b>__checkSysVersion</b>(<i></i>) |
|
964 |
|
965 <p> |
|
966 Private method to check the use of sys.version and sys.version_info. |
|
967 </p> |
|
968 <a NAME="MiscellaneousChecker.__checkTuple" ID="MiscellaneousChecker.__checkTuple"></a> |
|
969 <h4>MiscellaneousChecker.__checkTuple</h4> |
|
970 <b>__checkTuple</b>(<i></i>) |
|
971 |
|
972 <p> |
|
973 Private method to check for one element tuples. |
|
974 </p> |
|
975 <a NAME="MiscellaneousChecker.__dictShouldBeChecked" ID="MiscellaneousChecker.__dictShouldBeChecked"></a> |
|
976 <h4>MiscellaneousChecker.__dictShouldBeChecked</h4> |
|
977 <b>__dictShouldBeChecked</b>(<i>node</i>) |
|
978 |
|
979 <p> |
|
980 Private function to test, if the node should be checked. |
|
981 </p> |
|
982 <dl> |
|
983 |
|
984 <dt><i>node</i></dt> |
|
985 <dd> |
|
986 reference to the AST node |
|
987 </dd> |
|
988 </dl> |
|
989 <dl> |
|
990 <dt>Returns:</dt> |
|
991 <dd> |
|
992 flag indicating to check the node |
|
993 </dd> |
|
994 </dl> |
|
995 <dl> |
|
996 <dt>Return Type:</dt> |
|
997 <dd> |
|
998 bool |
|
999 </dd> |
|
1000 </dl> |
|
1001 <a NAME="MiscellaneousChecker.__error" ID="MiscellaneousChecker.__error"></a> |
|
1002 <h4>MiscellaneousChecker.__error</h4> |
|
1003 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
|
1004 |
|
1005 <p> |
|
1006 Private method to record an issue. |
|
1007 </p> |
|
1008 <dl> |
|
1009 |
|
1010 <dt><i>lineNumber</i> (int)</dt> |
|
1011 <dd> |
|
1012 line number of the issue |
|
1013 </dd> |
|
1014 <dt><i>offset</i> (int)</dt> |
|
1015 <dd> |
|
1016 position within line of the issue |
|
1017 </dd> |
|
1018 <dt><i>code</i> (str)</dt> |
|
1019 <dd> |
|
1020 message code |
|
1021 </dd> |
|
1022 <dt><i>args</i> (list)</dt> |
|
1023 <dd> |
|
1024 arguments for the message |
|
1025 </dd> |
|
1026 </dl> |
|
1027 <a NAME="MiscellaneousChecker.__generateTree" ID="MiscellaneousChecker.__generateTree"></a> |
|
1028 <h4>MiscellaneousChecker.__generateTree</h4> |
|
1029 <b>__generateTree</b>(<i></i>) |
|
1030 |
|
1031 <p> |
|
1032 Private method to generate an AST for our source. |
|
1033 </p> |
|
1034 <dl> |
|
1035 <dt>Returns:</dt> |
|
1036 <dd> |
|
1037 generated AST |
|
1038 </dd> |
|
1039 </dl> |
|
1040 <dl> |
|
1041 <dt>Return Type:</dt> |
|
1042 <dd> |
|
1043 ast.AST |
|
1044 </dd> |
|
1045 </dl> |
|
1046 <a NAME="MiscellaneousChecker.__getCoding" ID="MiscellaneousChecker.__getCoding"></a> |
|
1047 <h4>MiscellaneousChecker.__getCoding</h4> |
|
1048 <b>__getCoding</b>(<i></i>) |
|
1049 |
|
1050 <p> |
|
1051 Private method to get the defined coding of the source. |
|
1052 </p> |
|
1053 <dl> |
|
1054 <dt>Returns:</dt> |
|
1055 <dd> |
|
1056 tuple containing the line number and the coding |
|
1057 </dd> |
|
1058 </dl> |
|
1059 <dl> |
|
1060 <dt>Return Type:</dt> |
|
1061 <dd> |
|
1062 tuple of int and str |
|
1063 </dd> |
|
1064 </dl> |
|
1065 <a NAME="MiscellaneousChecker.__getFields" ID="MiscellaneousChecker.__getFields"></a> |
|
1066 <h4>MiscellaneousChecker.__getFields</h4> |
|
1067 <b>__getFields</b>(<i>string</i>) |
|
1068 |
|
1069 <p> |
|
1070 Private method to extract the format field information. |
|
1071 </p> |
|
1072 <dl> |
|
1073 |
|
1074 <dt><i>string</i> (str)</dt> |
|
1075 <dd> |
|
1076 format string to be parsed |
|
1077 </dd> |
|
1078 </dl> |
|
1079 <dl> |
|
1080 <dt>Returns:</dt> |
|
1081 <dd> |
|
1082 format field information as a tuple with fields, implicit |
|
1083 field definitions present and explicit field definitions present |
|
1084 </dd> |
|
1085 </dl> |
|
1086 <dl> |
|
1087 <dt>Return Type:</dt> |
|
1088 <dd> |
|
1089 tuple of set of str, bool, bool |
|
1090 </dd> |
|
1091 </dl> |
|
1092 <a NAME="MiscellaneousChecker.__ignoreCode" ID="MiscellaneousChecker.__ignoreCode"></a> |
|
1093 <h4>MiscellaneousChecker.__ignoreCode</h4> |
|
1094 <b>__ignoreCode</b>(<i>code</i>) |
|
1095 |
|
1096 <p> |
|
1097 Private method to check if the message code should be ignored. |
|
1098 </p> |
|
1099 <dl> |
|
1100 |
|
1101 <dt><i>code</i> (str)</dt> |
|
1102 <dd> |
|
1103 message code to check for |
|
1104 </dd> |
|
1105 </dl> |
|
1106 <dl> |
|
1107 <dt>Returns:</dt> |
|
1108 <dd> |
|
1109 flag indicating to ignore the given code |
|
1110 </dd> |
|
1111 </dl> |
|
1112 <dl> |
|
1113 <dt>Return Type:</dt> |
|
1114 <dd> |
|
1115 bool |
|
1116 </dd> |
|
1117 </dl> |
|
1118 <a NAME="MiscellaneousChecker.__reportInvalidSyntax" ID="MiscellaneousChecker.__reportInvalidSyntax"></a> |
|
1119 <h4>MiscellaneousChecker.__reportInvalidSyntax</h4> |
|
1120 <b>__reportInvalidSyntax</b>(<i></i>) |
|
1121 |
|
1122 <p> |
|
1123 Private method to report a syntax error. |
|
1124 </p> |
|
1125 <a NAME="MiscellaneousChecker.run" ID="MiscellaneousChecker.run"></a> |
|
1126 <h4>MiscellaneousChecker.run</h4> |
|
1127 <b>run</b>(<i></i>) |
|
1128 |
|
1129 <p> |
|
1130 Public method to check the given source against miscellaneous |
|
1131 conditions. |
|
1132 </p> |
|
1133 <div align="right"><a href="#top">Up</a></div> |
|
1134 <hr /> |
|
1135 <hr /> |
|
1136 <a NAME="NameFinder" ID="NameFinder"></a> |
|
1137 <h2>NameFinder</h2> |
|
1138 |
|
1139 <p> |
|
1140 Class to extract a name out of a tree of nodes. |
|
1141 </p> |
|
1142 <h3>Derived from</h3> |
|
1143 ast.NodeVisitor |
|
1144 <h3>Class Attributes</h3> |
|
1145 |
|
1146 <table> |
|
1147 <tr><td>None</td></tr> |
|
1148 </table> |
|
1149 <h3>Class Methods</h3> |
|
1150 |
|
1151 <table> |
|
1152 <tr><td>None</td></tr> |
|
1153 </table> |
|
1154 <h3>Methods</h3> |
|
1155 |
|
1156 <table> |
|
1157 |
|
1158 <tr> |
|
1159 <td><a href="#NameFinder.__init__">NameFinder</a></td> |
|
1160 <td>Constructor</td> |
|
1161 </tr> |
|
1162 <tr> |
|
1163 <td><a href="#NameFinder.getNames">getNames</a></td> |
|
1164 <td>Public method to return the extracted names and Name nodes.</td> |
|
1165 </tr> |
|
1166 <tr> |
|
1167 <td><a href="#NameFinder.visit">visit</a></td> |
|
1168 <td>Public method to traverse a given AST node.</td> |
|
1169 </tr> |
|
1170 <tr> |
|
1171 <td><a href="#NameFinder.visit_Name">visit_Name</a></td> |
|
1172 <td>Public method to handle 'Name' nodes.</td> |
|
1173 </tr> |
|
1174 </table> |
|
1175 <h3>Static Methods</h3> |
|
1176 |
|
1177 <table> |
|
1178 <tr><td>None</td></tr> |
|
1179 </table> |
|
1180 |
|
1181 <a NAME="NameFinder.__init__" ID="NameFinder.__init__"></a> |
|
1182 <h4>NameFinder (Constructor)</h4> |
|
1183 <b>NameFinder</b>(<i></i>) |
|
1184 |
|
1185 <p> |
|
1186 Constructor |
|
1187 </p> |
|
1188 <a NAME="NameFinder.getNames" ID="NameFinder.getNames"></a> |
|
1189 <h4>NameFinder.getNames</h4> |
|
1190 <b>getNames</b>(<i></i>) |
|
1191 |
|
1192 <p> |
|
1193 Public method to return the extracted names and Name nodes. |
|
1194 </p> |
|
1195 <dl> |
|
1196 <dt>Returns:</dt> |
|
1197 <dd> |
|
1198 dictionary containing the names as keys and the list of nodes |
|
1199 </dd> |
|
1200 </dl> |
|
1201 <dl> |
|
1202 <dt>Return Type:</dt> |
|
1203 <dd> |
|
1204 dict |
|
1205 </dd> |
|
1206 </dl> |
|
1207 <a NAME="NameFinder.visit" ID="NameFinder.visit"></a> |
|
1208 <h4>NameFinder.visit</h4> |
|
1209 <b>visit</b>(<i>node</i>) |
|
1210 |
|
1211 <p> |
|
1212 Public method to traverse a given AST node. |
|
1213 </p> |
|
1214 <dl> |
|
1215 |
|
1216 <dt><i>node</i> (ast.Node)</dt> |
|
1217 <dd> |
|
1218 AST node to be traversed |
|
1219 </dd> |
|
1220 </dl> |
|
1221 <a NAME="NameFinder.visit_Name" ID="NameFinder.visit_Name"></a> |
|
1222 <h4>NameFinder.visit_Name</h4> |
|
1223 <b>visit_Name</b>(<i>node</i>) |
|
1224 |
|
1225 <p> |
|
1226 Public method to handle 'Name' nodes. |
|
1227 </p> |
|
1228 <dl> |
|
1229 |
|
1230 <dt><i>node</i> (ast.Name)</dt> |
|
1231 <dd> |
|
1232 reference to the node to be processed |
|
1233 </dd> |
|
1234 </dl> |
|
1235 <div align="right"><a href="#top">Up</a></div> |
|
1236 <hr /> |
|
1237 <hr /> |
|
1238 <a NAME="ReturnVisitor" ID="ReturnVisitor"></a> |
|
1239 <h2>ReturnVisitor</h2> |
|
1240 |
|
1241 <p> |
|
1242 Class implementing a node visitor to check return statements. |
|
1243 </p> |
|
1244 <h3>Derived from</h3> |
|
1245 ast.NodeVisitor |
|
1246 <h3>Class Attributes</h3> |
|
1247 |
|
1248 <table> |
|
1249 <tr><td>Assigns</td></tr><tr><td>Refs</td></tr><tr><td>Returns</td></tr> |
|
1250 </table> |
|
1251 <h3>Class Methods</h3> |
|
1252 |
|
1253 <table> |
|
1254 <tr><td>None</td></tr> |
|
1255 </table> |
|
1256 <h3>Methods</h3> |
|
1257 |
|
1258 <table> |
|
1259 |
|
1260 <tr> |
|
1261 <td><a href="#ReturnVisitor.__init__">ReturnVisitor</a></td> |
|
1262 <td>Constructor</td> |
|
1263 </tr> |
|
1264 <tr> |
|
1265 <td><a href="#ReturnVisitor.__checkFunction">__checkFunction</a></td> |
|
1266 <td>Private method to check a function definition node.</td> |
|
1267 </tr> |
|
1268 <tr> |
|
1269 <td><a href="#ReturnVisitor.__checkImplicitReturn">__checkImplicitReturn</a></td> |
|
1270 <td>Private method to check for an implicit return statement.</td> |
|
1271 </tr> |
|
1272 <tr> |
|
1273 <td><a href="#ReturnVisitor.__checkImplicitReturnValue">__checkImplicitReturnValue</a></td> |
|
1274 <td>Private method to check for implicit return values.</td> |
|
1275 </tr> |
|
1276 <tr> |
|
1277 <td><a href="#ReturnVisitor.__checkUnnecessaryAssign">__checkUnnecessaryAssign</a></td> |
|
1278 <td>Private method to check for an unnecessary assign statement.</td> |
|
1279 </tr> |
|
1280 <tr> |
|
1281 <td><a href="#ReturnVisitor.__checkUnnecessaryReturnNone">__checkUnnecessaryReturnNone</a></td> |
|
1282 <td>Private method to check for an unnecessary 'return None' statement.</td> |
|
1283 </tr> |
|
1284 <tr> |
|
1285 <td><a href="#ReturnVisitor.__hasRefsBeforeNextAssign">__hasRefsBeforeNextAssign</a></td> |
|
1286 <td>Private method to check for references before a following assign statement.</td> |
|
1287 </tr> |
|
1288 <tr> |
|
1289 <td><a href="#ReturnVisitor.__isFalse">__isFalse</a></td> |
|
1290 <td>Private method to check, if a node value is False.</td> |
|
1291 </tr> |
|
1292 <tr> |
|
1293 <td><a href="#ReturnVisitor.__isNone">__isNone</a></td> |
|
1294 <td>Private method to check, if a node value is None.</td> |
|
1295 </tr> |
|
1296 <tr> |
|
1297 <td><a href="#ReturnVisitor.__resultExists">__resultExists</a></td> |
|
1298 <td>Private method to check the existance of a return result.</td> |
|
1299 </tr> |
|
1300 <tr> |
|
1301 <td><a href="#ReturnVisitor.__visitAssignTarget">__visitAssignTarget</a></td> |
|
1302 <td>Private method to handle an assign target node.</td> |
|
1303 </tr> |
|
1304 <tr> |
|
1305 <td><a href="#ReturnVisitor.__visitLoop">__visitLoop</a></td> |
|
1306 <td>Private method to handle loop nodes.</td> |
|
1307 </tr> |
|
1308 <tr> |
|
1309 <td><a href="#ReturnVisitor.__visitWithStack">__visitWithStack</a></td> |
|
1310 <td>Private method to traverse a given function node using a stack.</td> |
|
1311 </tr> |
|
1312 <tr> |
|
1313 <td><a href="#ReturnVisitor.assigns">assigns</a></td> |
|
1314 <td>Public method to get the Assign nodes.</td> |
|
1315 </tr> |
|
1316 <tr> |
|
1317 <td><a href="#ReturnVisitor.refs">refs</a></td> |
|
1318 <td>Public method to get the References nodes.</td> |
|
1319 </tr> |
|
1320 <tr> |
|
1321 <td><a href="#ReturnVisitor.returns">returns</a></td> |
|
1322 <td>Public method to get the Return nodes.</td> |
|
1323 </tr> |
|
1324 <tr> |
|
1325 <td><a href="#ReturnVisitor.visit_Assign">visit_Assign</a></td> |
|
1326 <td>Public method to handle an assign node.</td> |
|
1327 </tr> |
|
1328 <tr> |
|
1329 <td><a href="#ReturnVisitor.visit_AsyncFor">visit_AsyncFor</a></td> |
|
1330 <td>Public method to handle an async for loop.</td> |
|
1331 </tr> |
|
1332 <tr> |
|
1333 <td><a href="#ReturnVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td> |
|
1334 <td>Public method to handle a function definition.</td> |
|
1335 </tr> |
|
1336 <tr> |
|
1337 <td><a href="#ReturnVisitor.visit_For">visit_For</a></td> |
|
1338 <td>Public method to handle a for loop.</td> |
|
1339 </tr> |
|
1340 <tr> |
|
1341 <td><a href="#ReturnVisitor.visit_FunctionDef">visit_FunctionDef</a></td> |
|
1342 <td>Public method to handle a function definition.</td> |
|
1343 </tr> |
|
1344 <tr> |
|
1345 <td><a href="#ReturnVisitor.visit_Name">visit_Name</a></td> |
|
1346 <td>Public method to handle a name node.</td> |
|
1347 </tr> |
|
1348 <tr> |
|
1349 <td><a href="#ReturnVisitor.visit_Return">visit_Return</a></td> |
|
1350 <td>Public method to handle a return node.</td> |
|
1351 </tr> |
|
1352 <tr> |
|
1353 <td><a href="#ReturnVisitor.visit_While">visit_While</a></td> |
|
1354 <td>Public method to handle a while loop.</td> |
|
1355 </tr> |
|
1356 </table> |
|
1357 <h3>Static Methods</h3> |
|
1358 |
|
1359 <table> |
|
1360 <tr><td>None</td></tr> |
|
1361 </table> |
|
1362 |
|
1363 <a NAME="ReturnVisitor.__init__" ID="ReturnVisitor.__init__"></a> |
|
1364 <h4>ReturnVisitor (Constructor)</h4> |
|
1365 <b>ReturnVisitor</b>(<i></i>) |
|
1366 |
|
1367 <p> |
|
1368 Constructor |
|
1369 </p> |
|
1370 <a NAME="ReturnVisitor.__checkFunction" ID="ReturnVisitor.__checkFunction"></a> |
|
1371 <h4>ReturnVisitor.__checkFunction</h4> |
|
1372 <b>__checkFunction</b>(<i>node</i>) |
|
1373 |
|
1374 <p> |
|
1375 Private method to check a function definition node. |
|
1376 </p> |
|
1377 <dl> |
|
1378 |
|
1379 <dt><i>node</i> (ast.AsyncFunctionDef or ast.FunctionDef)</dt> |
|
1380 <dd> |
|
1381 reference to the node to check |
|
1382 </dd> |
|
1383 </dl> |
|
1384 <a NAME="ReturnVisitor.__checkImplicitReturn" ID="ReturnVisitor.__checkImplicitReturn"></a> |
|
1385 <h4>ReturnVisitor.__checkImplicitReturn</h4> |
|
1386 <b>__checkImplicitReturn</b>(<i>node</i>) |
|
1387 |
|
1388 <p> |
|
1389 Private method to check for an implicit return statement. |
|
1390 </p> |
|
1391 <dl> |
|
1392 |
|
1393 <dt><i>node</i> (ast.AST)</dt> |
|
1394 <dd> |
|
1395 reference to the node to check |
|
1396 </dd> |
|
1397 </dl> |
|
1398 <a NAME="ReturnVisitor.__checkImplicitReturnValue" ID="ReturnVisitor.__checkImplicitReturnValue"></a> |
|
1399 <h4>ReturnVisitor.__checkImplicitReturnValue</h4> |
|
1400 <b>__checkImplicitReturnValue</b>(<i></i>) |
|
1401 |
|
1402 <p> |
|
1403 Private method to check for implicit return values. |
|
1404 </p> |
|
1405 <a NAME="ReturnVisitor.__checkUnnecessaryAssign" ID="ReturnVisitor.__checkUnnecessaryAssign"></a> |
|
1406 <h4>ReturnVisitor.__checkUnnecessaryAssign</h4> |
|
1407 <b>__checkUnnecessaryAssign</b>(<i>node</i>) |
|
1408 |
|
1409 <p> |
|
1410 Private method to check for an unnecessary assign statement. |
|
1411 </p> |
|
1412 <dl> |
|
1413 |
|
1414 <dt><i>node</i> (ast.AST)</dt> |
|
1415 <dd> |
|
1416 reference to the node to check |
|
1417 </dd> |
|
1418 </dl> |
|
1419 <a NAME="ReturnVisitor.__checkUnnecessaryReturnNone" ID="ReturnVisitor.__checkUnnecessaryReturnNone"></a> |
|
1420 <h4>ReturnVisitor.__checkUnnecessaryReturnNone</h4> |
|
1421 <b>__checkUnnecessaryReturnNone</b>(<i></i>) |
|
1422 |
|
1423 <p> |
|
1424 Private method to check for an unnecessary 'return None' statement. |
|
1425 </p> |
|
1426 <a NAME="ReturnVisitor.__hasRefsBeforeNextAssign" ID="ReturnVisitor.__hasRefsBeforeNextAssign"></a> |
|
1427 <h4>ReturnVisitor.__hasRefsBeforeNextAssign</h4> |
|
1428 <b>__hasRefsBeforeNextAssign</b>(<i>varname, returnLineno</i>) |
|
1429 |
|
1430 <p> |
|
1431 Private method to check for references before a following assign |
|
1432 statement. |
|
1433 </p> |
|
1434 <dl> |
|
1435 |
|
1436 <dt><i>varname</i> (str)</dt> |
|
1437 <dd> |
|
1438 variable name to check for |
|
1439 </dd> |
|
1440 <dt><i>returnLineno</i> (int)</dt> |
|
1441 <dd> |
|
1442 line number of the return statement |
|
1443 </dd> |
|
1444 </dl> |
|
1445 <dl> |
|
1446 <dt>Returns:</dt> |
|
1447 <dd> |
|
1448 flag indicating the existence of references |
|
1449 </dd> |
|
1450 </dl> |
|
1451 <dl> |
|
1452 <dt>Return Type:</dt> |
|
1453 <dd> |
|
1454 bool |
|
1455 </dd> |
|
1456 </dl> |
|
1457 <a NAME="ReturnVisitor.__isFalse" ID="ReturnVisitor.__isFalse"></a> |
|
1458 <h4>ReturnVisitor.__isFalse</h4> |
|
1459 <b>__isFalse</b>(<i>node</i>) |
|
1460 |
|
1461 <p> |
|
1462 Private method to check, if a node value is False. |
|
1463 </p> |
|
1464 <dl> |
|
1465 |
|
1466 <dt><i>node</i> (ast.AST)</dt> |
|
1467 <dd> |
|
1468 reference to the node to check |
|
1469 </dd> |
|
1470 </dl> |
|
1471 <dl> |
|
1472 <dt>Returns:</dt> |
|
1473 <dd> |
|
1474 flag indicating the node contains a False value |
|
1475 </dd> |
|
1476 </dl> |
|
1477 <dl> |
|
1478 <dt>Return Type:</dt> |
|
1479 <dd> |
|
1480 bool |
|
1481 </dd> |
|
1482 </dl> |
|
1483 <a NAME="ReturnVisitor.__isNone" ID="ReturnVisitor.__isNone"></a> |
|
1484 <h4>ReturnVisitor.__isNone</h4> |
|
1485 <b>__isNone</b>(<i>node</i>) |
|
1486 |
|
1487 <p> |
|
1488 Private method to check, if a node value is None. |
|
1489 </p> |
|
1490 <dl> |
|
1491 |
|
1492 <dt><i>node</i> (ast.AST)</dt> |
|
1493 <dd> |
|
1494 reference to the node to check |
|
1495 </dd> |
|
1496 </dl> |
|
1497 <dl> |
|
1498 <dt>Returns:</dt> |
|
1499 <dd> |
|
1500 flag indicating the node contains a None value |
|
1501 </dd> |
|
1502 </dl> |
|
1503 <dl> |
|
1504 <dt>Return Type:</dt> |
|
1505 <dd> |
|
1506 bool |
|
1507 </dd> |
|
1508 </dl> |
|
1509 <a NAME="ReturnVisitor.__resultExists" ID="ReturnVisitor.__resultExists"></a> |
|
1510 <h4>ReturnVisitor.__resultExists</h4> |
|
1511 <b>__resultExists</b>(<i></i>) |
|
1512 |
|
1513 <p> |
|
1514 Private method to check the existance of a return result. |
|
1515 </p> |
|
1516 <dl> |
|
1517 <dt>Returns:</dt> |
|
1518 <dd> |
|
1519 flag indicating the existence of a return result |
|
1520 </dd> |
|
1521 </dl> |
|
1522 <dl> |
|
1523 <dt>Return Type:</dt> |
|
1524 <dd> |
|
1525 bool |
|
1526 </dd> |
|
1527 </dl> |
|
1528 <a NAME="ReturnVisitor.__visitAssignTarget" ID="ReturnVisitor.__visitAssignTarget"></a> |
|
1529 <h4>ReturnVisitor.__visitAssignTarget</h4> |
|
1530 <b>__visitAssignTarget</b>(<i>node</i>) |
|
1531 |
|
1532 <p> |
|
1533 Private method to handle an assign target node. |
|
1534 </p> |
|
1535 <dl> |
|
1536 |
|
1537 <dt><i>node</i> (ast.AST)</dt> |
|
1538 <dd> |
|
1539 reference to the node to handle |
|
1540 </dd> |
|
1541 </dl> |
|
1542 <a NAME="ReturnVisitor.__visitLoop" ID="ReturnVisitor.__visitLoop"></a> |
|
1543 <h4>ReturnVisitor.__visitLoop</h4> |
|
1544 <b>__visitLoop</b>(<i>node</i>) |
|
1545 |
|
1546 <p> |
|
1547 Private method to handle loop nodes. |
|
1548 </p> |
|
1549 <dl> |
|
1550 |
|
1551 <dt><i>node</i> (ast.For, ast.AsyncFor or ast.While)</dt> |
|
1552 <dd> |
|
1553 reference to the loop node to handle |
|
1554 </dd> |
|
1555 </dl> |
|
1556 <a NAME="ReturnVisitor.__visitWithStack" ID="ReturnVisitor.__visitWithStack"></a> |
|
1557 <h4>ReturnVisitor.__visitWithStack</h4> |
|
1558 <b>__visitWithStack</b>(<i>node</i>) |
|
1559 |
|
1560 <p> |
|
1561 Private method to traverse a given function node using a stack. |
|
1562 </p> |
|
1563 <dl> |
|
1564 |
|
1565 <dt><i>node</i> (ast.FunctionDef or ast.AsyncFunctionDef)</dt> |
|
1566 <dd> |
|
1567 AST node to be traversed |
|
1568 </dd> |
|
1569 </dl> |
|
1570 <a NAME="ReturnVisitor.assigns" ID="ReturnVisitor.assigns"></a> |
|
1571 <h4>ReturnVisitor.assigns</h4> |
|
1572 <b>assigns</b>(<i></i>) |
|
1573 |
|
1574 <p> |
|
1575 Public method to get the Assign nodes. |
|
1576 </p> |
|
1577 <dl> |
|
1578 <dt>Returns:</dt> |
|
1579 <dd> |
|
1580 dictionary containing the node name as key and line number |
|
1581 as value |
|
1582 </dd> |
|
1583 </dl> |
|
1584 <dl> |
|
1585 <dt>Return Type:</dt> |
|
1586 <dd> |
|
1587 dict |
|
1588 </dd> |
|
1589 </dl> |
|
1590 <a NAME="ReturnVisitor.refs" ID="ReturnVisitor.refs"></a> |
|
1591 <h4>ReturnVisitor.refs</h4> |
|
1592 <b>refs</b>(<i></i>) |
|
1593 |
|
1594 <p> |
|
1595 Public method to get the References nodes. |
|
1596 </p> |
|
1597 <dl> |
|
1598 <dt>Returns:</dt> |
|
1599 <dd> |
|
1600 dictionary containing the node name as key and line number |
|
1601 as value |
|
1602 </dd> |
|
1603 </dl> |
|
1604 <dl> |
|
1605 <dt>Return Type:</dt> |
|
1606 <dd> |
|
1607 dict |
|
1608 </dd> |
|
1609 </dl> |
|
1610 <a NAME="ReturnVisitor.returns" ID="ReturnVisitor.returns"></a> |
|
1611 <h4>ReturnVisitor.returns</h4> |
|
1612 <b>returns</b>(<i></i>) |
|
1613 |
|
1614 <p> |
|
1615 Public method to get the Return nodes. |
|
1616 </p> |
|
1617 <dl> |
|
1618 <dt>Returns:</dt> |
|
1619 <dd> |
|
1620 dictionary containing the node name as key and line number |
|
1621 as value |
|
1622 </dd> |
|
1623 </dl> |
|
1624 <dl> |
|
1625 <dt>Return Type:</dt> |
|
1626 <dd> |
|
1627 dict |
|
1628 </dd> |
|
1629 </dl> |
|
1630 <a NAME="ReturnVisitor.visit_Assign" ID="ReturnVisitor.visit_Assign"></a> |
|
1631 <h4>ReturnVisitor.visit_Assign</h4> |
|
1632 <b>visit_Assign</b>(<i>node</i>) |
|
1633 |
|
1634 <p> |
|
1635 Public method to handle an assign node. |
|
1636 </p> |
|
1637 <dl> |
|
1638 |
|
1639 <dt><i>node</i> (ast.Assign)</dt> |
|
1640 <dd> |
|
1641 reference to the node to handle |
|
1642 </dd> |
|
1643 </dl> |
|
1644 <a NAME="ReturnVisitor.visit_AsyncFor" ID="ReturnVisitor.visit_AsyncFor"></a> |
|
1645 <h4>ReturnVisitor.visit_AsyncFor</h4> |
|
1646 <b>visit_AsyncFor</b>(<i>node</i>) |
|
1647 |
|
1648 <p> |
|
1649 Public method to handle an async for loop. |
|
1650 </p> |
|
1651 <dl> |
|
1652 |
|
1653 <dt><i>node</i> (ast.AsyncFor)</dt> |
|
1654 <dd> |
|
1655 reference to the async for node to handle |
|
1656 </dd> |
|
1657 </dl> |
|
1658 <a NAME="ReturnVisitor.visit_AsyncFunctionDef" ID="ReturnVisitor.visit_AsyncFunctionDef"></a> |
|
1659 <h4>ReturnVisitor.visit_AsyncFunctionDef</h4> |
|
1660 <b>visit_AsyncFunctionDef</b>(<i>node</i>) |
|
1661 |
|
1662 <p> |
|
1663 Public method to handle a function definition. |
|
1664 </p> |
|
1665 <dl> |
|
1666 |
|
1667 <dt><i>node</i> (ast.AsyncFunctionDef)</dt> |
|
1668 <dd> |
|
1669 reference to the node to handle |
|
1670 </dd> |
|
1671 </dl> |
|
1672 <a NAME="ReturnVisitor.visit_For" ID="ReturnVisitor.visit_For"></a> |
|
1673 <h4>ReturnVisitor.visit_For</h4> |
|
1674 <b>visit_For</b>(<i>node</i>) |
|
1675 |
|
1676 <p> |
|
1677 Public method to handle a for loop. |
|
1678 </p> |
|
1679 <dl> |
|
1680 |
|
1681 <dt><i>node</i> (ast.For)</dt> |
|
1682 <dd> |
|
1683 reference to the for node to handle |
|
1684 </dd> |
|
1685 </dl> |
|
1686 <a NAME="ReturnVisitor.visit_FunctionDef" ID="ReturnVisitor.visit_FunctionDef"></a> |
|
1687 <h4>ReturnVisitor.visit_FunctionDef</h4> |
|
1688 <b>visit_FunctionDef</b>(<i>node</i>) |
|
1689 |
|
1690 <p> |
|
1691 Public method to handle a function definition. |
|
1692 </p> |
|
1693 <dl> |
|
1694 |
|
1695 <dt><i>node</i> (ast.FunctionDef)</dt> |
|
1696 <dd> |
|
1697 reference to the node to handle |
|
1698 </dd> |
|
1699 </dl> |
|
1700 <a NAME="ReturnVisitor.visit_Name" ID="ReturnVisitor.visit_Name"></a> |
|
1701 <h4>ReturnVisitor.visit_Name</h4> |
|
1702 <b>visit_Name</b>(<i>node</i>) |
|
1703 |
|
1704 <p> |
|
1705 Public method to handle a name node. |
|
1706 </p> |
|
1707 <dl> |
|
1708 |
|
1709 <dt><i>node</i> (ast.Name)</dt> |
|
1710 <dd> |
|
1711 reference to the node to handle |
|
1712 </dd> |
|
1713 </dl> |
|
1714 <a NAME="ReturnVisitor.visit_Return" ID="ReturnVisitor.visit_Return"></a> |
|
1715 <h4>ReturnVisitor.visit_Return</h4> |
|
1716 <b>visit_Return</b>(<i>node</i>) |
|
1717 |
|
1718 <p> |
|
1719 Public method to handle a return node. |
|
1720 </p> |
|
1721 <dl> |
|
1722 |
|
1723 <dt><i>node</i> (ast.Return)</dt> |
|
1724 <dd> |
|
1725 reference to the node to handle |
|
1726 </dd> |
|
1727 </dl> |
|
1728 <a NAME="ReturnVisitor.visit_While" ID="ReturnVisitor.visit_While"></a> |
|
1729 <h4>ReturnVisitor.visit_While</h4> |
|
1730 <b>visit_While</b>(<i>node</i>) |
|
1731 |
|
1732 <p> |
|
1733 Public method to handle a while loop. |
|
1734 </p> |
|
1735 <dl> |
|
1736 |
|
1737 <dt><i>node</i> (ast.While)</dt> |
|
1738 <dd> |
|
1739 reference to the while node to handle |
|
1740 </dd> |
|
1741 </dl> |
|
1742 <div align="right"><a href="#top">Up</a></div> |
|
1743 <hr /> |
|
1744 <hr /> |
|
1745 <a NAME="SysVersionVisitor" ID="SysVersionVisitor"></a> |
|
1746 <h2>SysVersionVisitor</h2> |
|
1747 |
|
1748 <p> |
|
1749 Class implementing a node visitor to check the use of sys.version and |
|
1750 sys.version_info. |
|
1751 </p> |
|
1752 <p> |
|
1753 Note: This class is modelled after flake8-2020 checker. |
|
1754 </p> |
|
1755 <h3>Derived from</h3> |
|
1756 ast.NodeVisitor |
|
1757 <h3>Class Attributes</h3> |
|
1758 |
|
1759 <table> |
|
1760 <tr><td>None</td></tr> |
|
1761 </table> |
|
1762 <h3>Class Methods</h3> |
|
1763 |
|
1764 <table> |
|
1765 <tr><td>None</td></tr> |
|
1766 </table> |
|
1767 <h3>Methods</h3> |
|
1768 |
|
1769 <table> |
|
1770 |
|
1771 <tr> |
|
1772 <td><a href="#SysVersionVisitor.__init__">SysVersionVisitor</a></td> |
|
1773 <td>Constructor</td> |
|
1774 </tr> |
|
1775 <tr> |
|
1776 <td><a href="#SysVersionVisitor.__isSys">__isSys</a></td> |
|
1777 <td>Private method to check for a reference to sys attribute.</td> |
|
1778 </tr> |
|
1779 <tr> |
|
1780 <td><a href="#SysVersionVisitor.__isSysVersionUpperSlice">__isSysVersionUpperSlice</a></td> |
|
1781 <td>Private method to check the upper slice of sys.version.</td> |
|
1782 </tr> |
|
1783 <tr> |
|
1784 <td><a href="#SysVersionVisitor.visit_Attribute">visit_Attribute</a></td> |
|
1785 <td>Public method to handle an attribute.</td> |
|
1786 </tr> |
|
1787 <tr> |
|
1788 <td><a href="#SysVersionVisitor.visit_Compare">visit_Compare</a></td> |
|
1789 <td>Public method to handle a comparison.</td> |
|
1790 </tr> |
|
1791 <tr> |
|
1792 <td><a href="#SysVersionVisitor.visit_ImportFrom">visit_ImportFrom</a></td> |
|
1793 <td>Public method to handle a from ...</td> |
|
1794 </tr> |
|
1795 <tr> |
|
1796 <td><a href="#SysVersionVisitor.visit_Name">visit_Name</a></td> |
|
1797 <td>Public method to handle an name.</td> |
|
1798 </tr> |
|
1799 <tr> |
|
1800 <td><a href="#SysVersionVisitor.visit_Subscript">visit_Subscript</a></td> |
|
1801 <td>Public method to handle a subscript.</td> |
|
1802 </tr> |
|
1803 </table> |
|
1804 <h3>Static Methods</h3> |
|
1805 |
|
1806 <table> |
|
1807 <tr><td>None</td></tr> |
|
1808 </table> |
|
1809 |
|
1810 <a NAME="SysVersionVisitor.__init__" ID="SysVersionVisitor.__init__"></a> |
|
1811 <h4>SysVersionVisitor (Constructor)</h4> |
|
1812 <b>SysVersionVisitor</b>(<i></i>) |
|
1813 |
|
1814 <p> |
|
1815 Constructor |
|
1816 </p> |
|
1817 <a NAME="SysVersionVisitor.__isSys" ID="SysVersionVisitor.__isSys"></a> |
|
1818 <h4>SysVersionVisitor.__isSys</h4> |
|
1819 <b>__isSys</b>(<i>attr, node</i>) |
|
1820 |
|
1821 <p> |
|
1822 Private method to check for a reference to sys attribute. |
|
1823 </p> |
|
1824 <dl> |
|
1825 |
|
1826 <dt><i>attr</i> (str)</dt> |
|
1827 <dd> |
|
1828 attribute name |
|
1829 </dd> |
|
1830 <dt><i>node</i> (ast.Node)</dt> |
|
1831 <dd> |
|
1832 reference to the node to be checked |
|
1833 </dd> |
|
1834 </dl> |
|
1835 <dl> |
|
1836 <dt>Returns:</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.__isSysVersionUpperSlice" ID="SysVersionVisitor.__isSysVersionUpperSlice"></a> |
|
1848 <h4>SysVersionVisitor.__isSysVersionUpperSlice</h4> |
|
1849 <b>__isSysVersionUpperSlice</b>(<i>node, n</i>) |
|
1850 |
|
1851 <p> |
|
1852 Private method to check the upper slice of sys.version. |
|
1853 </p> |
|
1854 <dl> |
|
1855 |
|
1856 <dt><i>node</i> (ast.Node)</dt> |
|
1857 <dd> |
|
1858 reference to the node to be checked |
|
1859 </dd> |
|
1860 <dt><i>n</i> (int)</dt> |
|
1861 <dd> |
|
1862 slice value to check against |
|
1863 </dd> |
|
1864 </dl> |
|
1865 <dl> |
|
1866 <dt>Returns:</dt> |
|
1867 <dd> |
|
1868 flag indicating a match |
|
1869 </dd> |
|
1870 </dl> |
|
1871 <dl> |
|
1872 <dt>Return Type:</dt> |
|
1873 <dd> |
|
1874 bool |
|
1875 </dd> |
|
1876 </dl> |
|
1877 <a NAME="SysVersionVisitor.visit_Attribute" ID="SysVersionVisitor.visit_Attribute"></a> |
|
1878 <h4>SysVersionVisitor.visit_Attribute</h4> |
|
1879 <b>visit_Attribute</b>(<i>node</i>) |
|
1880 |
|
1881 <p> |
|
1882 Public method to handle an attribute. |
|
1883 </p> |
|
1884 <dl> |
|
1885 |
|
1886 <dt><i>node</i> (ast.Attribute)</dt> |
|
1887 <dd> |
|
1888 reference to the node to be processed |
|
1889 </dd> |
|
1890 </dl> |
|
1891 <a NAME="SysVersionVisitor.visit_Compare" ID="SysVersionVisitor.visit_Compare"></a> |
|
1892 <h4>SysVersionVisitor.visit_Compare</h4> |
|
1893 <b>visit_Compare</b>(<i>node</i>) |
|
1894 |
|
1895 <p> |
|
1896 Public method to handle a comparison. |
|
1897 </p> |
|
1898 <dl> |
|
1899 |
|
1900 <dt><i>node</i> (ast.Compare)</dt> |
|
1901 <dd> |
|
1902 reference to the node to be processed |
|
1903 </dd> |
|
1904 </dl> |
|
1905 <a NAME="SysVersionVisitor.visit_ImportFrom" ID="SysVersionVisitor.visit_ImportFrom"></a> |
|
1906 <h4>SysVersionVisitor.visit_ImportFrom</h4> |
|
1907 <b>visit_ImportFrom</b>(<i>node</i>) |
|
1908 |
|
1909 <p> |
|
1910 Public method to handle a from ... import ... statement. |
|
1911 </p> |
|
1912 <dl> |
|
1913 |
|
1914 <dt><i>node</i> (ast.ImportFrom)</dt> |
|
1915 <dd> |
|
1916 reference to the node to be processed |
|
1917 </dd> |
|
1918 </dl> |
|
1919 <a NAME="SysVersionVisitor.visit_Name" ID="SysVersionVisitor.visit_Name"></a> |
|
1920 <h4>SysVersionVisitor.visit_Name</h4> |
|
1921 <b>visit_Name</b>(<i>node</i>) |
|
1922 |
|
1923 <p> |
|
1924 Public method to handle an name. |
|
1925 </p> |
|
1926 <dl> |
|
1927 |
|
1928 <dt><i>node</i> (ast.Name)</dt> |
|
1929 <dd> |
|
1930 reference to the node to be processed |
|
1931 </dd> |
|
1932 </dl> |
|
1933 <a NAME="SysVersionVisitor.visit_Subscript" ID="SysVersionVisitor.visit_Subscript"></a> |
|
1934 <h4>SysVersionVisitor.visit_Subscript</h4> |
|
1935 <b>visit_Subscript</b>(<i>node</i>) |
|
1936 |
|
1937 <p> |
|
1938 Public method to handle a subscript. |
|
1939 </p> |
|
1940 <dl> |
|
1941 |
|
1942 <dt><i>node</i> (ast.Subscript)</dt> |
|
1943 <dd> |
|
1944 reference to the node to be processed |
|
1945 </dd> |
|
1946 </dl> |
|
1947 <div align="right"><a href="#top">Up</a></div> |
|
1948 <hr /> |
|
1949 <hr /> |
|
1950 <a NAME="TextVisitor" ID="TextVisitor"></a> |
|
1951 <h2>TextVisitor</h2> |
|
1952 |
|
1953 <p> |
|
1954 Class implementing a node visitor for bytes and str instances. |
|
1955 </p> |
|
1956 <p> |
|
1957 It tries to detect docstrings as string of the first expression of each |
|
1958 module, class or function. |
|
1959 </p> |
|
1960 <h3>Derived from</h3> |
|
1961 ast.NodeVisitor |
|
1962 <h3>Class Attributes</h3> |
|
1963 |
|
1964 <table> |
|
1965 <tr><td>None</td></tr> |
|
1966 </table> |
|
1967 <h3>Class Methods</h3> |
|
1968 |
|
1969 <table> |
|
1970 <tr><td>None</td></tr> |
|
1971 </table> |
|
1972 <h3>Methods</h3> |
|
1973 |
|
1974 <table> |
|
1975 |
|
1976 <tr> |
|
1977 <td><a href="#TextVisitor.__init__">TextVisitor</a></td> |
|
1978 <td>Constructor</td> |
|
1979 </tr> |
|
1980 <tr> |
|
1981 <td><a href="#TextVisitor.__addNode">__addNode</a></td> |
|
1982 <td>Private method to add a node to our list of nodes.</td> |
|
1983 </tr> |
|
1984 <tr> |
|
1985 <td><a href="#TextVisitor.__visitBody">__visitBody</a></td> |
|
1986 <td>Private method to traverse the body of the node manually.</td> |
|
1987 </tr> |
|
1988 <tr> |
|
1989 <td><a href="#TextVisitor.__visitDefinition">__visitDefinition</a></td> |
|
1990 <td>Private method handling class and function definitions.</td> |
|
1991 </tr> |
|
1992 <tr> |
|
1993 <td><a href="#TextVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td> |
|
1994 <td>Public method to handle an asynchronous function definition.</td> |
|
1995 </tr> |
|
1996 <tr> |
|
1997 <td><a href="#TextVisitor.visit_Bytes">visit_Bytes</a></td> |
|
1998 <td>Public method to record a bytes node.</td> |
|
1999 </tr> |
|
2000 <tr> |
|
2001 <td><a href="#TextVisitor.visit_Call">visit_Call</a></td> |
|
2002 <td>Public method to handle a function call.</td> |
|
2003 </tr> |
|
2004 <tr> |
|
2005 <td><a href="#TextVisitor.visit_ClassDef">visit_ClassDef</a></td> |
|
2006 <td>Public method to handle a class definition.</td> |
|
2007 </tr> |
|
2008 <tr> |
|
2009 <td><a href="#TextVisitor.visit_Constant">visit_Constant</a></td> |
|
2010 <td>Public method to handle constant nodes.</td> |
|
2011 </tr> |
|
2012 <tr> |
|
2013 <td><a href="#TextVisitor.visit_FunctionDef">visit_FunctionDef</a></td> |
|
2014 <td>Public method to handle a function definition.</td> |
|
2015 </tr> |
|
2016 <tr> |
|
2017 <td><a href="#TextVisitor.visit_Module">visit_Module</a></td> |
|
2018 <td>Public method to handle a module.</td> |
|
2019 </tr> |
|
2020 <tr> |
|
2021 <td><a href="#TextVisitor.visit_Str">visit_Str</a></td> |
|
2022 <td>Public method to record a string node.</td> |
|
2023 </tr> |
|
2024 </table> |
|
2025 <h3>Static Methods</h3> |
|
2026 |
|
2027 <table> |
|
2028 <tr><td>None</td></tr> |
|
2029 </table> |
|
2030 |
|
2031 <a NAME="TextVisitor.__init__" ID="TextVisitor.__init__"></a> |
|
2032 <h4>TextVisitor (Constructor)</h4> |
|
2033 <b>TextVisitor</b>(<i></i>) |
|
2034 |
|
2035 <p> |
|
2036 Constructor |
|
2037 </p> |
|
2038 <a NAME="TextVisitor.__addNode" ID="TextVisitor.__addNode"></a> |
|
2039 <h4>TextVisitor.__addNode</h4> |
|
2040 <b>__addNode</b>(<i>node</i>) |
|
2041 |
|
2042 <p> |
|
2043 Private method to add a node to our list of nodes. |
|
2044 </p> |
|
2045 <dl> |
|
2046 |
|
2047 <dt><i>node</i> (ast.AST)</dt> |
|
2048 <dd> |
|
2049 reference to the node to add |
|
2050 </dd> |
|
2051 </dl> |
|
2052 <a NAME="TextVisitor.__visitBody" ID="TextVisitor.__visitBody"></a> |
|
2053 <h4>TextVisitor.__visitBody</h4> |
|
2054 <b>__visitBody</b>(<i>node</i>) |
|
2055 |
|
2056 <p> |
|
2057 Private method to traverse the body of the node manually. |
|
2058 </p> |
|
2059 <p> |
|
2060 If the first node is an expression which contains a string or bytes it |
|
2061 marks that as a docstring. |
|
2062 </p> |
|
2063 <dl> |
|
2064 |
|
2065 <dt><i>node</i> (ast.AST)</dt> |
|
2066 <dd> |
|
2067 reference to the node to traverse |
|
2068 </dd> |
|
2069 </dl> |
|
2070 <a NAME="TextVisitor.__visitDefinition" ID="TextVisitor.__visitDefinition"></a> |
|
2071 <h4>TextVisitor.__visitDefinition</h4> |
|
2072 <b>__visitDefinition</b>(<i>node</i>) |
|
2073 |
|
2074 <p> |
|
2075 Private method handling class and function definitions. |
|
2076 </p> |
|
2077 <dl> |
|
2078 |
|
2079 <dt><i>node</i> (ast.FunctionDef, ast.AsyncFunctionDef or ast.ClassDef)</dt> |
|
2080 <dd> |
|
2081 reference to the node to handle |
|
2082 </dd> |
|
2083 </dl> |
|
2084 <a NAME="TextVisitor.visit_AsyncFunctionDef" ID="TextVisitor.visit_AsyncFunctionDef"></a> |
|
2085 <h4>TextVisitor.visit_AsyncFunctionDef</h4> |
|
2086 <b>visit_AsyncFunctionDef</b>(<i>node</i>) |
|
2087 |
|
2088 <p> |
|
2089 Public method to handle an asynchronous function definition. |
|
2090 </p> |
|
2091 <dl> |
|
2092 |
|
2093 <dt><i>node</i> (ast.AsyncFunctionDef)</dt> |
|
2094 <dd> |
|
2095 reference to the node to handle |
|
2096 </dd> |
|
2097 </dl> |
|
2098 <a NAME="TextVisitor.visit_Bytes" ID="TextVisitor.visit_Bytes"></a> |
|
2099 <h4>TextVisitor.visit_Bytes</h4> |
|
2100 <b>visit_Bytes</b>(<i>node</i>) |
|
2101 |
|
2102 <p> |
|
2103 Public method to record a bytes node. |
|
2104 </p> |
|
2105 <dl> |
|
2106 |
|
2107 <dt><i>node</i> (ast.Bytes)</dt> |
|
2108 <dd> |
|
2109 reference to the bytes node |
|
2110 </dd> |
|
2111 </dl> |
|
2112 <a NAME="TextVisitor.visit_Call" ID="TextVisitor.visit_Call"></a> |
|
2113 <h4>TextVisitor.visit_Call</h4> |
|
2114 <b>visit_Call</b>(<i>node</i>) |
|
2115 |
|
2116 <p> |
|
2117 Public method to handle a function call. |
|
2118 </p> |
|
2119 <dl> |
|
2120 |
|
2121 <dt><i>node</i> (ast.Call)</dt> |
|
2122 <dd> |
|
2123 reference to the node to handle |
|
2124 </dd> |
|
2125 </dl> |
|
2126 <a NAME="TextVisitor.visit_ClassDef" ID="TextVisitor.visit_ClassDef"></a> |
|
2127 <h4>TextVisitor.visit_ClassDef</h4> |
|
2128 <b>visit_ClassDef</b>(<i>node</i>) |
|
2129 |
|
2130 <p> |
|
2131 Public method to handle a class definition. |
|
2132 </p> |
|
2133 <dl> |
|
2134 |
|
2135 <dt><i>node</i> (ast.ClassDef)</dt> |
|
2136 <dd> |
|
2137 reference to the node to handle |
|
2138 </dd> |
|
2139 </dl> |
|
2140 <a NAME="TextVisitor.visit_Constant" ID="TextVisitor.visit_Constant"></a> |
|
2141 <h4>TextVisitor.visit_Constant</h4> |
|
2142 <b>visit_Constant</b>(<i>node</i>) |
|
2143 |
|
2144 <p> |
|
2145 Public method to handle constant nodes. |
|
2146 </p> |
|
2147 <dl> |
|
2148 |
|
2149 <dt><i>node</i> (ast.Constant)</dt> |
|
2150 <dd> |
|
2151 reference to the bytes node |
|
2152 </dd> |
|
2153 </dl> |
|
2154 <a NAME="TextVisitor.visit_FunctionDef" ID="TextVisitor.visit_FunctionDef"></a> |
|
2155 <h4>TextVisitor.visit_FunctionDef</h4> |
|
2156 <b>visit_FunctionDef</b>(<i>node</i>) |
|
2157 |
|
2158 <p> |
|
2159 Public method to handle a function definition. |
|
2160 </p> |
|
2161 <dl> |
|
2162 |
|
2163 <dt><i>node</i> (ast.FunctionDef)</dt> |
|
2164 <dd> |
|
2165 reference to the node to handle |
|
2166 </dd> |
|
2167 </dl> |
|
2168 <a NAME="TextVisitor.visit_Module" ID="TextVisitor.visit_Module"></a> |
|
2169 <h4>TextVisitor.visit_Module</h4> |
|
2170 <b>visit_Module</b>(<i>node</i>) |
|
2171 |
|
2172 <p> |
|
2173 Public method to handle a module. |
|
2174 </p> |
|
2175 <dl> |
|
2176 |
|
2177 <dt><i>node</i> (ast.Module)</dt> |
|
2178 <dd> |
|
2179 reference to the node to handle |
|
2180 </dd> |
|
2181 </dl> |
|
2182 <a NAME="TextVisitor.visit_Str" ID="TextVisitor.visit_Str"></a> |
|
2183 <h4>TextVisitor.visit_Str</h4> |
|
2184 <b>visit_Str</b>(<i>node</i>) |
|
2185 |
|
2186 <p> |
|
2187 Public method to record a string node. |
|
2188 </p> |
|
2189 <dl> |
|
2190 |
|
2191 <dt><i>node</i> (ast.Str)</dt> |
|
2192 <dd> |
|
2193 reference to the string node |
|
2194 </dd> |
|
2195 </dl> |
|
2196 <div align="right"><a href="#top">Up</a></div> |
|
2197 <hr /> |
|
2198 <hr /> |
|
2199 <a NAME="composeCallPath" ID="composeCallPath"></a> |
|
2200 <h2>composeCallPath</h2> |
|
2201 <b>composeCallPath</b>(<i>node</i>) |
|
2202 |
|
2203 <p> |
|
2204 Generator function to assemble the call path of a given node. |
|
2205 </p> |
|
2206 <dl> |
|
2207 |
|
2208 <dt><i>node</i> (ast.Node)</dt> |
|
2209 <dd> |
|
2210 node to assemble call path for |
|
2211 </dd> |
|
2212 </dl> |
|
2213 <dl> |
|
2214 <dt>Returns:</dt> |
|
2215 <dd> |
|
2216 call path components |
|
2217 </dd> |
|
2218 </dl> |
|
2219 <dl> |
|
2220 <dt>Return Type:</dt> |
|
2221 <dd> |
|
2222 str |
|
2223 </dd> |
|
2224 </dl> |
|
2225 <div align="right"><a href="#top">Up</a></div> |
|
2226 <hr /> |
|
2227 </body></html> |