src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Unused.UnusedChecker.html

branch
eric7
changeset 10054
d7a47f0cff2b
child 10070
9f5758c0fec1
equal deleted inserted replaced
10053:9914b7b4b11c 10054:d7a47f0cff2b
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Unused.UnusedChecker</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.Unused.UnusedChecker</h1>
10
11 <p>
12 Module implementing a checker for unused arguments, variables, ... .
13 </p>
14 <h3>Global Attributes</h3>
15
16 <table>
17 <tr><td>GlobalVariableStoreInfo</td></tr>
18 </table>
19 <h3>Classes</h3>
20
21 <table>
22
23 <tr>
24 <td><a href="#FunctionFinder">FunctionFinder</a></td>
25 <td>Class to find all defined functions and methods.</td>
26 </tr>
27 <tr>
28 <td><a href="#GlobalVariableLoadCounter">GlobalVariableLoadCounter</a></td>
29 <td>Class to find all defined global variables and count their usages.</td>
30 </tr>
31 <tr>
32 <td><a href="#NameFinder">NameFinder</a></td>
33 <td>Class to find the used argument names.</td>
34 </tr>
35 <tr>
36 <td><a href="#UnusedChecker">UnusedChecker</a></td>
37 <td>Class implementing a checker for unused arguments, variables, ...</td>
38 </tr>
39 </table>
40 <h3>Functions</h3>
41
42 <table>
43 <tr><td>None</td></tr>
44 </table>
45 <hr />
46 <hr />
47 <a NAME="FunctionFinder" ID="FunctionFinder"></a>
48 <h2>FunctionFinder</h2>
49
50 <p>
51 Class to find all defined functions and methods.
52 </p>
53 <h3>Derived from</h3>
54 ast.NodeVisitor
55 <h3>Class Attributes</h3>
56
57 <table>
58 <tr><td>visit_AsyncFunctionDef</td></tr>
59 </table>
60 <h3>Class Methods</h3>
61
62 <table>
63 <tr><td>None</td></tr>
64 </table>
65 <h3>Methods</h3>
66
67 <table>
68
69 <tr>
70 <td><a href="#FunctionFinder.__init__">FunctionFinder</a></td>
71 <td>Constructor</td>
72 </tr>
73 <tr>
74 <td><a href="#FunctionFinder.__visitFunctionTypes">__visitFunctionTypes</a></td>
75 <td>Private method to handle an AST node defining a function or lambda.</td>
76 </tr>
77 <tr>
78 <td><a href="#FunctionFinder.functionNodes">functionNodes</a></td>
79 <td>Public method to get the list of detected functions and lambdas.</td>
80 </tr>
81 </table>
82 <h3>Static Methods</h3>
83
84 <table>
85 <tr><td>None</td></tr>
86 </table>
87
88 <a NAME="FunctionFinder.__init__" ID="FunctionFinder.__init__"></a>
89 <h4>FunctionFinder (Constructor)</h4>
90 <b>FunctionFinder</b>(<i>onlyTopLevel=False</i>)
91
92 <p>
93 Constructor
94 </p>
95 <dl>
96
97 <dt><i>onlyTopLevel</i> (bool (optional))</dt>
98 <dd>
99 flag indicating to search for top level functions only
100 (defaults to False)
101 </dd>
102 </dl>
103 <a NAME="FunctionFinder.__visitFunctionTypes" ID="FunctionFinder.__visitFunctionTypes"></a>
104 <h4>FunctionFinder.__visitFunctionTypes</h4>
105 <b>__visitFunctionTypes</b>(<i>functionNode</i>)
106
107 <p>
108 Private method to handle an AST node defining a function or lambda.
109 </p>
110 <dl>
111
112 <dt><i>functionNode</i> (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)</dt>
113 <dd>
114 reference to the node defining a function or lambda
115 </dd>
116 </dl>
117 <a NAME="FunctionFinder.functionNodes" ID="FunctionFinder.functionNodes"></a>
118 <h4>FunctionFinder.functionNodes</h4>
119 <b>functionNodes</b>(<i></i>)
120
121 <p>
122 Public method to get the list of detected functions and lambdas.
123 </p>
124 <dl>
125 <dt>Return:</dt>
126 <dd>
127 list of detected functions and lambdas
128 </dd>
129 </dl>
130 <dl>
131 <dt>Return Type:</dt>
132 <dd>
133 list of ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda
134 </dd>
135 </dl>
136 <div align="right"><a href="#top">Up</a></div>
137 <hr />
138 <hr />
139 <a NAME="GlobalVariableLoadCounter" ID="GlobalVariableLoadCounter"></a>
140 <h2>GlobalVariableLoadCounter</h2>
141
142 <p>
143 Class to find all defined global variables and count their usages.
144 </p>
145 <h3>Derived from</h3>
146 ast.NodeVisitor
147 <h3>Class Attributes</h3>
148
149 <table>
150 <tr><td>None</td></tr>
151 </table>
152 <h3>Class Methods</h3>
153
154 <table>
155 <tr><td>None</td></tr>
156 </table>
157 <h3>Methods</h3>
158
159 <table>
160
161 <tr>
162 <td><a href="#GlobalVariableLoadCounter.__init__">GlobalVariableLoadCounter</a></td>
163 <td>Constructor</td>
164 </tr>
165 <tr>
166 <td><a href="#GlobalVariableLoadCounter.getLoads">getLoads</a></td>
167 <td>Public method to get an iterator of the detected variable loads.</td>
168 </tr>
169 <tr>
170 <td><a href="#GlobalVariableLoadCounter.getStoreInfo">getStoreInfo</a></td>
171 <td>Public method to get the store info data of a given variable ID.</td>
172 </tr>
173 <tr>
174 <td><a href="#GlobalVariableLoadCounter.visit_Name">visit_Name</a></td>
175 <td>Public method to record the definition and use of a global variable.</td>
176 </tr>
177 </table>
178 <h3>Static Methods</h3>
179
180 <table>
181 <tr><td>None</td></tr>
182 </table>
183
184 <a NAME="GlobalVariableLoadCounter.__init__" ID="GlobalVariableLoadCounter.__init__"></a>
185 <h4>GlobalVariableLoadCounter (Constructor)</h4>
186 <b>GlobalVariableLoadCounter</b>(<i></i>)
187
188 <p>
189 Constructor
190 </p>
191 <a NAME="GlobalVariableLoadCounter.getLoads" ID="GlobalVariableLoadCounter.getLoads"></a>
192 <h4>GlobalVariableLoadCounter.getLoads</h4>
193 <b>getLoads</b>(<i></i>)
194
195 <p>
196 Public method to get an iterator of the detected variable loads.
197 </p>
198 <dl>
199 <dt>Return:</dt>
200 <dd>
201 DESCRIPTION
202 </dd>
203 </dl>
204 <dl>
205 <dt>Return Type:</dt>
206 <dd>
207 TYPE
208 </dd>
209 </dl>
210 <a NAME="GlobalVariableLoadCounter.getStoreInfo" ID="GlobalVariableLoadCounter.getStoreInfo"></a>
211 <h4>GlobalVariableLoadCounter.getStoreInfo</h4>
212 <b>getStoreInfo</b>(<i>variableId</i>)
213
214 <p>
215 Public method to get the store info data of a given variable ID.
216 </p>
217 <dl>
218
219 <dt><i>variableId</i> (str)</dt>
220 <dd>
221 variable ID to retrieve the store info for
222 </dd>
223 </dl>
224 <dl>
225 <dt>Return:</dt>
226 <dd>
227 named tuple containing the line number and column offset
228 </dd>
229 </dl>
230 <dl>
231 <dt>Return Type:</dt>
232 <dd>
233 GlobalVariableStoreInfo
234 </dd>
235 </dl>
236 <a NAME="GlobalVariableLoadCounter.visit_Name" ID="GlobalVariableLoadCounter.visit_Name"></a>
237 <h4>GlobalVariableLoadCounter.visit_Name</h4>
238 <b>visit_Name</b>(<i>nameNode</i>)
239
240 <p>
241 Public method to record the definition and use of a global variable.
242 </p>
243 <dl>
244
245 <dt><i>nameNode</i> (ast.Name)</dt>
246 <dd>
247 reference to the name node to be processed
248 </dd>
249 </dl>
250 <div align="right"><a href="#top">Up</a></div>
251 <hr />
252 <hr />
253 <a NAME="NameFinder" ID="NameFinder"></a>
254 <h2>NameFinder</h2>
255
256 <p>
257 Class to find the used argument names.
258 </p>
259 <h3>Derived from</h3>
260 ast.NodeVisitor
261 <h3>Class Attributes</h3>
262
263 <table>
264 <tr><td>None</td></tr>
265 </table>
266 <h3>Class Methods</h3>
267
268 <table>
269 <tr><td>None</td></tr>
270 </table>
271 <h3>Methods</h3>
272
273 <table>
274
275 <tr>
276 <td><a href="#NameFinder.visit_Name">visit_Name</a></td>
277 <td>Public method to check a Name node.</td>
278 </tr>
279 </table>
280 <h3>Static Methods</h3>
281
282 <table>
283 <tr><td>None</td></tr>
284 </table>
285
286 <a NAME="NameFinder.visit_Name" ID="NameFinder.visit_Name"></a>
287 <h4>NameFinder.visit_Name</h4>
288 <b>visit_Name</b>(<i>name</i>)
289
290 <p>
291 Public method to check a Name node.
292 </p>
293 <dl>
294
295 <dt><i>name</i> (ast.Name)</dt>
296 <dd>
297 reference to the name node to be checked
298 </dd>
299 </dl>
300 <div align="right"><a href="#top">Up</a></div>
301 <hr />
302 <hr />
303 <a NAME="UnusedChecker" ID="UnusedChecker"></a>
304 <h2>UnusedChecker</h2>
305
306 <p>
307 Class implementing a checker for unused arguments, variables, ... .
308 </p>
309 <h3>Derived from</h3>
310 None
311 <h3>Class Attributes</h3>
312
313 <table>
314 <tr><td>Codes</td></tr>
315 </table>
316 <h3>Class Methods</h3>
317
318 <table>
319 <tr><td>None</td></tr>
320 </table>
321 <h3>Methods</h3>
322
323 <table>
324
325 <tr>
326 <td><a href="#UnusedChecker.__init__">UnusedChecker</a></td>
327 <td>Constructor</td>
328 </tr>
329 <tr>
330 <td><a href="#UnusedChecker.__checkUnusedArguments">__checkUnusedArguments</a></td>
331 <td>Private method to check function and method definitions for unused arguments.</td>
332 </tr>
333 <tr>
334 <td><a href="#UnusedChecker.__checkUnusedGlobals">__checkUnusedGlobals</a></td>
335 <td>Private method to check for unused global variables.</td>
336 </tr>
337 <tr>
338 <td><a href="#UnusedChecker.__error">__error</a></td>
339 <td>Private method to record an issue.</td>
340 </tr>
341 <tr>
342 <td><a href="#UnusedChecker.__extractGlobalVariables">__extractGlobalVariables</a></td>
343 <td>Private method to get the names of all global variables.</td>
344 </tr>
345 <tr>
346 <td><a href="#UnusedChecker.__getArguments">__getArguments</a></td>
347 <td>Private method to get all argument names of the given function.</td>
348 </tr>
349 <tr>
350 <td><a href="#UnusedChecker.__getDecoratorNames">__getDecoratorNames</a></td>
351 <td>Private method to yield the decorator names of the function.</td>
352 </tr>
353 <tr>
354 <td><a href="#UnusedChecker.__getUnusedArguments">__getUnusedArguments</a></td>
355 <td>Private method to get a list of unused arguments of the given function.</td>
356 </tr>
357 <tr>
358 <td><a href="#UnusedChecker.__ignoreCode">__ignoreCode</a></td>
359 <td>Private method to check if the message code should be ignored.</td>
360 </tr>
361 <tr>
362 <td><a href="#UnusedChecker.__isDunderMethod">__isDunderMethod</a></td>
363 <td>Private method to check, if the function node defines a special function.</td>
364 </tr>
365 <tr>
366 <td><a href="#UnusedChecker.__isStubFunction">__isStubFunction</a></td>
367 <td>Private method to check, if the given function node defines a stub function.</td>
368 </tr>
369 <tr>
370 <td><a href="#UnusedChecker.run">run</a></td>
371 <td>Public method to check the given source against miscellaneous conditions.</td>
372 </tr>
373 </table>
374 <h3>Static Methods</h3>
375
376 <table>
377 <tr><td>None</td></tr>
378 </table>
379
380 <a NAME="UnusedChecker.__init__" ID="UnusedChecker.__init__"></a>
381 <h4>UnusedChecker (Constructor)</h4>
382 <b>UnusedChecker</b>(<i>source, filename, tree, select, ignore, expected, repeat, args</i>)
383
384 <p>
385 Constructor
386 </p>
387 <dl>
388
389 <dt><i>source</i> (list of str)</dt>
390 <dd>
391 source code to be checked
392 </dd>
393 <dt><i>filename</i> (str)</dt>
394 <dd>
395 name of the source file
396 </dd>
397 <dt><i>tree</i> (ast.Module)</dt>
398 <dd>
399 AST tree of the source code
400 </dd>
401 <dt><i>select</i> (list of str)</dt>
402 <dd>
403 list of selected codes
404 </dd>
405 <dt><i>ignore</i> (list of str)</dt>
406 <dd>
407 list of codes to be ignored
408 </dd>
409 <dt><i>expected</i> (list of str)</dt>
410 <dd>
411 list of expected codes
412 </dd>
413 <dt><i>repeat</i> (bool)</dt>
414 <dd>
415 flag indicating to report each occurrence of a code
416 </dd>
417 <dt><i>args</i> (dict)</dt>
418 <dd>
419 dictionary of arguments for the various checks
420 </dd>
421 </dl>
422 <a NAME="UnusedChecker.__checkUnusedArguments" ID="UnusedChecker.__checkUnusedArguments"></a>
423 <h4>UnusedChecker.__checkUnusedArguments</h4>
424 <b>__checkUnusedArguments</b>(<i></i>)
425
426 <p>
427 Private method to check function and method definitions for unused arguments.
428 </p>
429 <a NAME="UnusedChecker.__checkUnusedGlobals" ID="UnusedChecker.__checkUnusedGlobals"></a>
430 <h4>UnusedChecker.__checkUnusedGlobals</h4>
431 <b>__checkUnusedGlobals</b>(<i></i>)
432
433 <p>
434 Private method to check for unused global variables.
435 </p>
436 <a NAME="UnusedChecker.__error" ID="UnusedChecker.__error"></a>
437 <h4>UnusedChecker.__error</h4>
438 <b>__error</b>(<i>lineNumber, offset, code, *args</i>)
439
440 <p>
441 Private method to record an issue.
442 </p>
443 <dl>
444
445 <dt><i>lineNumber</i> (int)</dt>
446 <dd>
447 line number of the issue
448 </dd>
449 <dt><i>offset</i> (int)</dt>
450 <dd>
451 position within line of the issue
452 </dd>
453 <dt><i>code</i> (str)</dt>
454 <dd>
455 message code
456 </dd>
457 <dt><i>args</i> (list)</dt>
458 <dd>
459 arguments for the message
460 </dd>
461 </dl>
462 <a NAME="UnusedChecker.__extractGlobalVariables" ID="UnusedChecker.__extractGlobalVariables"></a>
463 <h4>UnusedChecker.__extractGlobalVariables</h4>
464 <b>__extractGlobalVariables</b>(<i></i>)
465
466 <p>
467 Private method to get the names of all global variables.
468 </p>
469 <dl>
470 <dt>Return:</dt>
471 <dd>
472 set containing the defined global variable names
473 </dd>
474 </dl>
475 <dl>
476 <dt>Return Type:</dt>
477 <dd>
478 set of str
479 </dd>
480 </dl>
481 <a NAME="UnusedChecker.__getArguments" ID="UnusedChecker.__getArguments"></a>
482 <h4>UnusedChecker.__getArguments</h4>
483 <b>__getArguments</b>(<i>functionNode</i>)
484
485 <p>
486 Private method to get all argument names of the given function.
487 </p>
488 <dl>
489
490 <dt><i>functionNode</i> (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)</dt>
491 <dd>
492 reference to the node defining the function or lambda
493 </dd>
494 </dl>
495 <dl>
496 <dt>Return:</dt>
497 <dd>
498 list of argument names
499 </dd>
500 </dl>
501 <dl>
502 <dt>Return Type:</dt>
503 <dd>
504 list of ast.arg
505 </dd>
506 </dl>
507 <a NAME="UnusedChecker.__getDecoratorNames" ID="UnusedChecker.__getDecoratorNames"></a>
508 <h4>UnusedChecker.__getDecoratorNames</h4>
509 <b>__getDecoratorNames</b>(<i>functionNode</i>)
510
511 <p>
512 Private method to yield the decorator names of the function.
513 </p>
514 <dl>
515
516 <dt><i>functionNode</i> (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)</dt>
517 <dd>
518 reference to the node defining the function or lambda
519 </dd>
520 </dl>
521 <dl>
522 <dt>Yield:</dt>
523 <dd>
524 decorator name
525 </dd>
526 </dl>
527 <dl>
528 <dt>Yield Type:</dt>
529 <dd>
530 str
531 </dd>
532 </dl>
533 <a NAME="UnusedChecker.__getUnusedArguments" ID="UnusedChecker.__getUnusedArguments"></a>
534 <h4>UnusedChecker.__getUnusedArguments</h4>
535 <b>__getUnusedArguments</b>(<i>functionNode</i>)
536
537 <p>
538 Private method to get a list of unused arguments of the given function.
539 </p>
540 <dl>
541
542 <dt><i>functionNode</i> (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)</dt>
543 <dd>
544 reference to the node defining the function or lambda
545 </dd>
546 </dl>
547 <dl>
548 <dt>Return:</dt>
549 <dd>
550 list of tuples of the argument position and the argument
551 </dd>
552 </dl>
553 <dl>
554 <dt>Return Type:</dt>
555 <dd>
556 list of tuples of (int, ast.arg)
557 </dd>
558 </dl>
559 <a NAME="UnusedChecker.__ignoreCode" ID="UnusedChecker.__ignoreCode"></a>
560 <h4>UnusedChecker.__ignoreCode</h4>
561 <b>__ignoreCode</b>(<i>code</i>)
562
563 <p>
564 Private method to check if the message code should be ignored.
565 </p>
566 <dl>
567
568 <dt><i>code</i> (str)</dt>
569 <dd>
570 message code to check for
571 </dd>
572 </dl>
573 <dl>
574 <dt>Return:</dt>
575 <dd>
576 flag indicating to ignore the given code
577 </dd>
578 </dl>
579 <dl>
580 <dt>Return Type:</dt>
581 <dd>
582 bool
583 </dd>
584 </dl>
585 <a NAME="UnusedChecker.__isDunderMethod" ID="UnusedChecker.__isDunderMethod"></a>
586 <h4>UnusedChecker.__isDunderMethod</h4>
587 <b>__isDunderMethod</b>(<i>functionNode</i>)
588
589 <p>
590 Private method to check, if the function node defines a special function.
591 </p>
592 <dl>
593
594 <dt><i>functionNode</i> (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)</dt>
595 <dd>
596 reference to the node defining the function or lambda
597 </dd>
598 </dl>
599 <dl>
600 <dt>Return:</dt>
601 <dd>
602 flag indicating a special function
603 </dd>
604 </dl>
605 <dl>
606 <dt>Return Type:</dt>
607 <dd>
608 bool
609 </dd>
610 </dl>
611 <a NAME="UnusedChecker.__isStubFunction" ID="UnusedChecker.__isStubFunction"></a>
612 <h4>UnusedChecker.__isStubFunction</h4>
613 <b>__isStubFunction</b>(<i>functionNode</i>)
614
615 <p>
616 Private method to check, if the given function node defines a stub function.
617 </p>
618 <dl>
619
620 <dt><i>functionNode</i> (ast.AsyncFunctionDef, ast.FunctionDef or ast.Lambda)</dt>
621 <dd>
622 reference to the node defining the function or lambda
623 </dd>
624 </dl>
625 <dl>
626 <dt>Return:</dt>
627 <dd>
628 flag indicating a stub function
629 </dd>
630 </dl>
631 <dl>
632 <dt>Return Type:</dt>
633 <dd>
634 bool
635 </dd>
636 </dl>
637 <a NAME="UnusedChecker.run" ID="UnusedChecker.run"></a>
638 <h4>UnusedChecker.run</h4>
639 <b>run</b>(<i></i>)
640
641 <p>
642 Public method to check the given source against miscellaneous
643 conditions.
644 </p>
645 <div align="right"><a href="#top">Up</a></div>
646 <hr />
647 </body></html>

eric ide

mercurial