eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor.html

branch
eric7
changeset 8372
e0227a7c850e
child 8596
d64760b2da50
equal deleted inserted replaced
8371:d6062691d424 8372:e0227a7c850e
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor</title>
4 <meta charset="UTF-8">
5 <style>
6 body {
7 background: #EDECE6;
8 margin: 0em 1em 10em 1em;
9 color: black;
10 }
11
12 h1 { color: white; background: #85774A; }
13 h2 { color: white; background: #85774A; }
14 h3 { color: white; background: #9D936E; }
15 h4 { color: white; background: #9D936E; }
16
17 a { color: #BA6D36; }
18
19 </style>
20 </head>
21 <body>
22 <a NAME="top" ID="top"></a>
23 <h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Simplify.SimplifyNodeVisitor</h1>
24
25 <p>
26 Module implementing a node visitor checking for code that could be simplified.
27 </p>
28 <h3>Global Attributes</h3>
29
30 <table>
31 <tr><td>AST_CONST_TYPES</td></tr><tr><td>BOOL_CONST_TYPES</td></tr><tr><td>STR_TYPES</td></tr>
32 </table>
33 <h3>Classes</h3>
34
35 <table>
36
37 <tr>
38 <td><a href="#SimplifyNodeVisitor">SimplifyNodeVisitor</a></td>
39 <td>Class to traverse the AST node tree and check for code that can be simplified.</td>
40 </tr>
41 </table>
42 <h3>Functions</h3>
43
44 <table>
45 <tr><td>None</td></tr>
46 </table>
47 <hr />
48 <hr />
49 <a NAME="SimplifyNodeVisitor" ID="SimplifyNodeVisitor"></a>
50 <h2>SimplifyNodeVisitor</h2>
51
52 <p>
53 Class to traverse the AST node tree and check for code that can be
54 simplified.
55 </p>
56 <h3>Derived from</h3>
57 ast.NodeVisitor
58 <h3>Class Attributes</h3>
59
60 <table>
61 <tr><td>None</td></tr>
62 </table>
63 <h3>Class Methods</h3>
64
65 <table>
66 <tr><td>None</td></tr>
67 </table>
68 <h3>Methods</h3>
69
70 <table>
71
72 <tr>
73 <td><a href="#SimplifyNodeVisitor.__init__">SimplifyNodeVisitor</a></td>
74 <td>Constructor</td>
75 </tr>
76 <tr>
77 <td><a href="#SimplifyNodeVisitor.__check101">__check101</a></td>
78 <td>Private method to check for duplicate isinstance() calls.</td>
79 </tr>
80 <tr>
81 <td><a href="#SimplifyNodeVisitor.__check102">__check102</a></td>
82 <td>Private method to check for nested if statements without else blocks.</td>
83 </tr>
84 <tr>
85 <td><a href="#SimplifyNodeVisitor.__check103">__check103</a></td>
86 <td>Private method to check for calls that wrap a condition to return a bool.</td>
87 </tr>
88 <tr>
89 <td><a href="#SimplifyNodeVisitor.__check104">__check104</a></td>
90 <td>Private method to check for "iterate and yield" patterns.</td>
91 </tr>
92 <tr>
93 <td><a href="#SimplifyNodeVisitor.__check105">__check105</a></td>
94 <td>Private method to check for "try-except-pass" patterns.</td>
95 </tr>
96 <tr>
97 <td><a href="#SimplifyNodeVisitor.__check106">__check106</a></td>
98 <td>Private method to check for calls where an exception is raised in else.</td>
99 </tr>
100 <tr>
101 <td><a href="#SimplifyNodeVisitor.__check107">__check107</a></td>
102 <td>Private method to check for calls where try/except and finally have 'return'.</td>
103 </tr>
104 <tr>
105 <td><a href="#SimplifyNodeVisitor.__check108">__check108</a></td>
106 <td>Private method to check for if-elses which could be a ternary operator assignment.</td>
107 </tr>
108 <tr>
109 <td><a href="#SimplifyNodeVisitor.__check109">__check109</a></td>
110 <td>Private method to check for multiple equalities with the same value are combined via "or".</td>
111 </tr>
112 <tr>
113 <td><a href="#SimplifyNodeVisitor.__check110_111">__check110_111</a></td>
114 <td>Private method to check if any / all could be used.</td>
115 </tr>
116 <tr>
117 <td><a href="#SimplifyNodeVisitor.__check112">__check112</a></td>
118 <td>Private method to check for non-capitalized calls to environment variables.</td>
119 </tr>
120 <tr>
121 <td><a href="#SimplifyNodeVisitor.__check113">__check113</a></td>
122 <td>Private method to check for loops in which "enumerate" should be used.</td>
123 </tr>
124 <tr>
125 <td><a href="#SimplifyNodeVisitor.__check114">__check114</a></td>
126 <td>Private method to check for alternative if clauses with identical bodies.</td>
127 </tr>
128 <tr>
129 <td><a href="#SimplifyNodeVisitor.__check115">__check115</a></td>
130 <td>Private method to to check for places where open() is called without a context handler.</td>
131 </tr>
132 <tr>
133 <td><a href="#SimplifyNodeVisitor.__check116">__check116</a></td>
134 <td>Private method to check for places with 3 or more consecutive if-statements with direct returns.</td>
135 </tr>
136 <tr>
137 <td><a href="#SimplifyNodeVisitor.__check117">__check117</a></td>
138 <td>Private method to check for multiple with-statements with same scope.</td>
139 </tr>
140 <tr>
141 <td><a href="#SimplifyNodeVisitor.__check118">__check118</a></td>
142 <td>Private method to check for usages of "key in dict.keys()".</td>
143 </tr>
144 <tr>
145 <td><a href="#SimplifyNodeVisitor.__check119">__check119</a></td>
146 <td>Private method to check for classes that should be "dataclasses".</td>
147 </tr>
148 <tr>
149 <td><a href="#SimplifyNodeVisitor.__check120_121">__check120_121</a></td>
150 <td>Private method to check for classes that inherit from object.</td>
151 </tr>
152 <tr>
153 <td><a href="#SimplifyNodeVisitor.__check122">__check122</a></td>
154 <td>Private method to check for all if-blocks which only check if a key is in a dictionary.</td>
155 </tr>
156 <tr>
157 <td><a href="#SimplifyNodeVisitor.__check181">__check181</a></td>
158 <td>Private method to check for assignments that could be converted into an augmented assignment.</td>
159 </tr>
160 <tr>
161 <td><a href="#SimplifyNodeVisitor.__check182">__check182</a></td>
162 <td>Private method to check for calls of type 'super()' that could be shortened to 'super()'.</td>
163 </tr>
164 <tr>
165 <td><a href="#SimplifyNodeVisitor.__check201">__check201</a></td>
166 <td>Private method to check for calls where an unary 'not' is used for an unequality.</td>
167 </tr>
168 <tr>
169 <td><a href="#SimplifyNodeVisitor.__check202">__check202</a></td>
170 <td>Private method to check for calls where an unary 'not' is used for an equality.</td>
171 </tr>
172 <tr>
173 <td><a href="#SimplifyNodeVisitor.__check203">__check203</a></td>
174 <td>Private method to check for calls where an unary 'not' is used for an in-check.</td>
175 </tr>
176 <tr>
177 <td><a href="#SimplifyNodeVisitor.__check204">__check204</a></td>
178 <td>Private method to check for calls of the type "not (a < b)".</td>
179 </tr>
180 <tr>
181 <td><a href="#SimplifyNodeVisitor.__check205">__check205</a></td>
182 <td>Private method to check for calls of the type "not (a <= b)".</td>
183 </tr>
184 <tr>
185 <td><a href="#SimplifyNodeVisitor.__check206">__check206</a></td>
186 <td>Private method to check for calls of the type "not (a > b)".</td>
187 </tr>
188 <tr>
189 <td><a href="#SimplifyNodeVisitor.__check207">__check207</a></td>
190 <td>Private method to check for calls of the type "not (a >= b)".</td>
191 </tr>
192 <tr>
193 <td><a href="#SimplifyNodeVisitor.__check208">__check208</a></td>
194 <td>Private method to check for calls of the type "not (not a)".</td>
195 </tr>
196 <tr>
197 <td><a href="#SimplifyNodeVisitor.__check211">__check211</a></td>
198 <td>Private method to check for calls of the type "True if a else False".</td>
199 </tr>
200 <tr>
201 <td><a href="#SimplifyNodeVisitor.__check212">__check212</a></td>
202 <td>Private method to check for calls of the type "False if a else True".</td>
203 </tr>
204 <tr>
205 <td><a href="#SimplifyNodeVisitor.__check213">__check213</a></td>
206 <td>Private method to check for calls of the type "b if not a else a".</td>
207 </tr>
208 <tr>
209 <td><a href="#SimplifyNodeVisitor.__check221">__check221</a></td>
210 <td>Private method to check for calls of the type "a and not a".</td>
211 </tr>
212 <tr>
213 <td><a href="#SimplifyNodeVisitor.__check222">__check222</a></td>
214 <td>Private method to check for calls of the type "a or not a".</td>
215 </tr>
216 <tr>
217 <td><a href="#SimplifyNodeVisitor.__check223">__check223</a></td>
218 <td>Private method to check for calls of the type "...</td>
219 </tr>
220 <tr>
221 <td><a href="#SimplifyNodeVisitor.__check224">__check224</a></td>
222 <td>Private method to check for calls of the type "...</td>
223 </tr>
224 <tr>
225 <td><a href="#SimplifyNodeVisitor.__check301">__check301</a></td>
226 <td>Private method to check for Yoda conditions.</td>
227 </tr>
228 <tr>
229 <td><a href="#SimplifyNodeVisitor.__check401">__check401</a></td>
230 <td>Private method to check for bare boolean function arguments.</td>
231 </tr>
232 <tr>
233 <td><a href="#SimplifyNodeVisitor.__check402">__check402</a></td>
234 <td>Private method to check for bare numeric function arguments.</td>
235 </tr>
236 <tr>
237 <td><a href="#SimplifyNodeVisitor.__getDuplicatedIsinstanceCall">__getDuplicatedIsinstanceCall</a></td>
238 <td>Private method to get a list of isinstance arguments which could be combined.</td>
239 </tr>
240 <tr>
241 <td><a href="#SimplifyNodeVisitor.__getIfBodyPairs">__getIfBodyPairs</a></td>
242 <td>Private method to extract a list of pairs of test and body for an If node.</td>
243 </tr>
244 <tr>
245 <td><a href="#SimplifyNodeVisitor.__isConstantIncrease">__isConstantIncrease</a></td>
246 <td>Private method check the given expression for being a constant increase.</td>
247 </tr>
248 <tr>
249 <td><a href="#SimplifyNodeVisitor.__isExceptionCheck">__isExceptionCheck</a></td>
250 <td>Private method to check, if the node is checking an exception.</td>
251 </tr>
252 <tr>
253 <td><a href="#SimplifyNodeVisitor.__isSameBody">__isSameBody</a></td>
254 <td>Private method check, if the given bodies are equivalent.</td>
255 </tr>
256 <tr>
257 <td><a href="#SimplifyNodeVisitor.__isSameExpression">__isSameExpression</a></td>
258 <td>Private method to check, if two expressions are equal.</td>
259 </tr>
260 <tr>
261 <td><a href="#SimplifyNodeVisitor.__isStatementEqual">__isStatementEqual</a></td>
262 <td>Private method to check, if two statements are equal.</td>
263 </tr>
264 <tr>
265 <td><a href="#SimplifyNodeVisitor.__negateTest">__negateTest</a></td>
266 <td>Private method negate the given Compare node.</td>
267 </tr>
268 <tr>
269 <td><a href="#SimplifyNodeVisitor.visit_Assign">visit_Assign</a></td>
270 <td>Public method to process an Assign node.</td>
271 </tr>
272 <tr>
273 <td><a href="#SimplifyNodeVisitor.visit_BoolOp">visit_BoolOp</a></td>
274 <td>Public method to process a BoolOp node.</td>
275 </tr>
276 <tr>
277 <td><a href="#SimplifyNodeVisitor.visit_Call">visit_Call</a></td>
278 <td>Public method to process a Call node.</td>
279 </tr>
280 <tr>
281 <td><a href="#SimplifyNodeVisitor.visit_ClassDef">visit_ClassDef</a></td>
282 <td>Public method to process a ClassDef node.</td>
283 </tr>
284 <tr>
285 <td><a href="#SimplifyNodeVisitor.visit_Compare">visit_Compare</a></td>
286 <td>Public method to process a Compare node.</td>
287 </tr>
288 <tr>
289 <td><a href="#SimplifyNodeVisitor.visit_Expr">visit_Expr</a></td>
290 <td>Public method to process an Expr node.</td>
291 </tr>
292 <tr>
293 <td><a href="#SimplifyNodeVisitor.visit_For">visit_For</a></td>
294 <td>Public method to process a For node.</td>
295 </tr>
296 <tr>
297 <td><a href="#SimplifyNodeVisitor.visit_If">visit_If</a></td>
298 <td>Public method to process an If node.</td>
299 </tr>
300 <tr>
301 <td><a href="#SimplifyNodeVisitor.visit_IfExp">visit_IfExp</a></td>
302 <td>Public method to process an IfExp node.</td>
303 </tr>
304 <tr>
305 <td><a href="#SimplifyNodeVisitor.visit_Try">visit_Try</a></td>
306 <td>Public method to process a Try node.</td>
307 </tr>
308 <tr>
309 <td><a href="#SimplifyNodeVisitor.visit_UnaryOp">visit_UnaryOp</a></td>
310 <td>Public method to process a UnaryOp node.</td>
311 </tr>
312 <tr>
313 <td><a href="#SimplifyNodeVisitor.visit_With">visit_With</a></td>
314 <td>Public method to process a With node.</td>
315 </tr>
316 </table>
317 <h3>Static Methods</h3>
318
319 <table>
320 <tr><td>None</td></tr>
321 </table>
322
323 <a NAME="SimplifyNodeVisitor.__init__" ID="SimplifyNodeVisitor.__init__"></a>
324 <h4>SimplifyNodeVisitor (Constructor)</h4>
325 <b>SimplifyNodeVisitor</b>(<i>errorCallback</i>)
326
327 <p>
328 Constructor
329 </p>
330 <dl>
331
332 <dt><i>errorCallback</i> (func)</dt>
333 <dd>
334 callback function to register an error
335 </dd>
336 </dl>
337 <a NAME="SimplifyNodeVisitor.__check101" ID="SimplifyNodeVisitor.__check101"></a>
338 <h4>SimplifyNodeVisitor.__check101</h4>
339 <b>__check101</b>(<i>node</i>)
340
341 <p>
342 Private method to check for duplicate isinstance() calls.
343 </p>
344 <dl>
345
346 <dt><i>node</i> (ast.BoolOp)</dt>
347 <dd>
348 reference to the AST node to be checked
349 </dd>
350 </dl>
351 <a NAME="SimplifyNodeVisitor.__check102" ID="SimplifyNodeVisitor.__check102"></a>
352 <h4>SimplifyNodeVisitor.__check102</h4>
353 <b>__check102</b>(<i>node</i>)
354
355 <p>
356 Private method to check for nested if statements without else blocks.
357 </p>
358 <dl>
359
360 <dt><i>node</i> (ast.If)</dt>
361 <dd>
362 reference to the AST node to be checked
363 </dd>
364 </dl>
365 <a NAME="SimplifyNodeVisitor.__check103" ID="SimplifyNodeVisitor.__check103"></a>
366 <h4>SimplifyNodeVisitor.__check103</h4>
367 <b>__check103</b>(<i>node</i>)
368
369 <p>
370 Private method to check for calls that wrap a condition to return
371 a bool.
372 </p>
373 <dl>
374
375 <dt><i>node</i> (ast.If)</dt>
376 <dd>
377 reference to the AST node to be checked
378 </dd>
379 </dl>
380 <a NAME="SimplifyNodeVisitor.__check104" ID="SimplifyNodeVisitor.__check104"></a>
381 <h4>SimplifyNodeVisitor.__check104</h4>
382 <b>__check104</b>(<i>node</i>)
383
384 <p>
385 Private method to check for "iterate and yield" patterns.
386 </p>
387 <dl>
388
389 <dt><i>node</i> (ast.For)</dt>
390 <dd>
391 reference to the AST node to be checked
392 </dd>
393 </dl>
394 <a NAME="SimplifyNodeVisitor.__check105" ID="SimplifyNodeVisitor.__check105"></a>
395 <h4>SimplifyNodeVisitor.__check105</h4>
396 <b>__check105</b>(<i>node</i>)
397
398 <p>
399 Private method to check for "try-except-pass" patterns.
400 </p>
401 <dl>
402
403 <dt><i>node</i> (ast.Try)</dt>
404 <dd>
405 reference to the AST node to be checked
406 </dd>
407 </dl>
408 <a NAME="SimplifyNodeVisitor.__check106" ID="SimplifyNodeVisitor.__check106"></a>
409 <h4>SimplifyNodeVisitor.__check106</h4>
410 <b>__check106</b>(<i>node</i>)
411
412 <p>
413 Private method to check for calls where an exception is raised in else.
414 </p>
415 <dl>
416
417 <dt><i>node</i> (ast.If)</dt>
418 <dd>
419 reference to the AST node to be checked
420 </dd>
421 </dl>
422 <a NAME="SimplifyNodeVisitor.__check107" ID="SimplifyNodeVisitor.__check107"></a>
423 <h4>SimplifyNodeVisitor.__check107</h4>
424 <b>__check107</b>(<i>node</i>)
425
426 <p>
427 Private method to check for calls where try/except and finally have
428 'return'.
429 </p>
430 <dl>
431
432 <dt><i>node</i> (ast.Try)</dt>
433 <dd>
434 reference to the AST node to be checked
435 </dd>
436 </dl>
437 <a NAME="SimplifyNodeVisitor.__check108" ID="SimplifyNodeVisitor.__check108"></a>
438 <h4>SimplifyNodeVisitor.__check108</h4>
439 <b>__check108</b>(<i>node</i>)
440
441 <p>
442 Private method to check for if-elses which could be a ternary
443 operator assignment.
444 </p>
445 <dl>
446
447 <dt><i>node</i> (ast.If)</dt>
448 <dd>
449 reference to the AST node to be checked
450 </dd>
451 </dl>
452 <a NAME="SimplifyNodeVisitor.__check109" ID="SimplifyNodeVisitor.__check109"></a>
453 <h4>SimplifyNodeVisitor.__check109</h4>
454 <b>__check109</b>(<i>node</i>)
455
456 <p>
457 Private method to check for multiple equalities with the same value
458 are combined via "or".
459 </p>
460 <dl>
461
462 <dt><i>node</i> (ast.BoolOp)</dt>
463 <dd>
464 reference to the AST node to be checked
465 </dd>
466 </dl>
467 <a NAME="SimplifyNodeVisitor.__check110_111" ID="SimplifyNodeVisitor.__check110_111"></a>
468 <h4>SimplifyNodeVisitor.__check110_111</h4>
469 <b>__check110_111</b>(<i>node</i>)
470
471 <p>
472 Private method to check if any / all could be used.
473 </p>
474 <dl>
475
476 <dt><i>node</i> (ast.For)</dt>
477 <dd>
478 reference to the AST node to be checked
479 </dd>
480 </dl>
481 <a NAME="SimplifyNodeVisitor.__check112" ID="SimplifyNodeVisitor.__check112"></a>
482 <h4>SimplifyNodeVisitor.__check112</h4>
483 <b>__check112</b>(<i>node</i>)
484
485 <p>
486 Private method to check for non-capitalized calls to environment
487 variables.
488 </p>
489 <dl>
490
491 <dt><i>node</i> (ast.Expr)</dt>
492 <dd>
493 reference to the AST node to be checked
494 </dd>
495 </dl>
496 <a NAME="SimplifyNodeVisitor.__check113" ID="SimplifyNodeVisitor.__check113"></a>
497 <h4>SimplifyNodeVisitor.__check113</h4>
498 <b>__check113</b>(<i>node</i>)
499
500 <p>
501 Private method to check for loops in which "enumerate" should be
502 used.
503 </p>
504 <dl>
505
506 <dt><i>node</i> (ast.For)</dt>
507 <dd>
508 reference to the AST node to be checked
509 </dd>
510 </dl>
511 <a NAME="SimplifyNodeVisitor.__check114" ID="SimplifyNodeVisitor.__check114"></a>
512 <h4>SimplifyNodeVisitor.__check114</h4>
513 <b>__check114</b>(<i>node</i>)
514
515 <p>
516 Private method to check for alternative if clauses with identical
517 bodies.
518 </p>
519 <dl>
520
521 <dt><i>node</i> (ast.If)</dt>
522 <dd>
523 reference to the AST node to be checked
524 </dd>
525 </dl>
526 <a NAME="SimplifyNodeVisitor.__check115" ID="SimplifyNodeVisitor.__check115"></a>
527 <h4>SimplifyNodeVisitor.__check115</h4>
528 <b>__check115</b>(<i>node</i>)
529
530 <p>
531 Private method to to check for places where open() is called without
532 a context handler.
533 </p>
534 <dl>
535
536 <dt><i>node</i> (ast.Call)</dt>
537 <dd>
538 reference to the AST node to be checked
539 </dd>
540 </dl>
541 <a NAME="SimplifyNodeVisitor.__check116" ID="SimplifyNodeVisitor.__check116"></a>
542 <h4>SimplifyNodeVisitor.__check116</h4>
543 <b>__check116</b>(<i>node</i>)
544
545 <p>
546 Private method to check for places with 3 or more consecutive
547 if-statements with direct returns.
548 </p>
549 <p>
550 * Each if-statement must be a check for equality with the
551 same variable
552 * Each if-statement must just have a "return"
553 * Else must also just have a return
554 </p>
555 <dl>
556
557 <dt><i>node</i> (ast.If)</dt>
558 <dd>
559 reference to the AST node to be checked
560 </dd>
561 </dl>
562 <a NAME="SimplifyNodeVisitor.__check117" ID="SimplifyNodeVisitor.__check117"></a>
563 <h4>SimplifyNodeVisitor.__check117</h4>
564 <b>__check117</b>(<i>node</i>)
565
566 <p>
567 Private method to check for multiple with-statements with same scope.
568 </p>
569 <dl>
570
571 <dt><i>node</i> (ast.With)</dt>
572 <dd>
573 reference to the AST node to be checked
574 </dd>
575 </dl>
576 <a NAME="SimplifyNodeVisitor.__check118" ID="SimplifyNodeVisitor.__check118"></a>
577 <h4>SimplifyNodeVisitor.__check118</h4>
578 <b>__check118</b>(<i>node</i>)
579
580 <p>
581 Private method to check for usages of "key in dict.keys()".
582 </p>
583 <dl>
584
585 <dt><i>node</i> (ast.Compare or ast.For)</dt>
586 <dd>
587 reference to the AST node to be checked
588 </dd>
589 </dl>
590 <a NAME="SimplifyNodeVisitor.__check119" ID="SimplifyNodeVisitor.__check119"></a>
591 <h4>SimplifyNodeVisitor.__check119</h4>
592 <b>__check119</b>(<i>node</i>)
593
594 <p>
595 Private method to check for classes that should be "dataclasses".
596 </p>
597 <dl>
598
599 <dt><i>node</i> (ast.ClassDef)</dt>
600 <dd>
601 reference to the AST node to be checked
602 </dd>
603 </dl>
604 <a NAME="SimplifyNodeVisitor.__check120_121" ID="SimplifyNodeVisitor.__check120_121"></a>
605 <h4>SimplifyNodeVisitor.__check120_121</h4>
606 <b>__check120_121</b>(<i>node</i>)
607
608 <p>
609 Private method to check for classes that inherit from object.
610 </p>
611 <dl>
612
613 <dt><i>node</i> (ast.ClassDef)</dt>
614 <dd>
615 reference to the AST node to be checked
616 </dd>
617 </dl>
618 <a NAME="SimplifyNodeVisitor.__check122" ID="SimplifyNodeVisitor.__check122"></a>
619 <h4>SimplifyNodeVisitor.__check122</h4>
620 <b>__check122</b>(<i>node</i>)
621
622 <p>
623 Private method to check for all if-blocks which only check if a key
624 is in a dictionary.
625 </p>
626 <dl>
627
628 <dt><i>node</i> (ast.If)</dt>
629 <dd>
630 reference to the AST node to be checked
631 </dd>
632 </dl>
633 <a NAME="SimplifyNodeVisitor.__check181" ID="SimplifyNodeVisitor.__check181"></a>
634 <h4>SimplifyNodeVisitor.__check181</h4>
635 <b>__check181</b>(<i>node</i>)
636
637 <p>
638 Private method to check for assignments that could be converted into
639 an augmented assignment.
640 </p>
641 <dl>
642
643 <dt><i>node</i> (ast.Assign)</dt>
644 <dd>
645 reference to the AST node to be checked
646 </dd>
647 </dl>
648 <a NAME="SimplifyNodeVisitor.__check182" ID="SimplifyNodeVisitor.__check182"></a>
649 <h4>SimplifyNodeVisitor.__check182</h4>
650 <b>__check182</b>(<i>node</i>)
651
652 <p>
653 Private method to check for calls of type 'super()' that could
654 be shortened to 'super()'.
655 </p>
656 <dl>
657
658 <dt><i>node</i> (ast.Call)</dt>
659 <dd>
660 reference to the AST node to be checked
661 </dd>
662 </dl>
663 <a NAME="SimplifyNodeVisitor.__check201" ID="SimplifyNodeVisitor.__check201"></a>
664 <h4>SimplifyNodeVisitor.__check201</h4>
665 <b>__check201</b>(<i>node</i>)
666
667 <p>
668 Private method to check for calls where an unary 'not' is used for
669 an unequality.
670 </p>
671 <dl>
672
673 <dt><i>node</i> (ast.UnaryOp)</dt>
674 <dd>
675 reference to the UnaryOp node
676 </dd>
677 </dl>
678 <a NAME="SimplifyNodeVisitor.__check202" ID="SimplifyNodeVisitor.__check202"></a>
679 <h4>SimplifyNodeVisitor.__check202</h4>
680 <b>__check202</b>(<i>node</i>)
681
682 <p>
683 Private method to check for calls where an unary 'not' is used for
684 an equality.
685 </p>
686 <dl>
687
688 <dt><i>node</i> (ast.UnaryOp)</dt>
689 <dd>
690 reference to the UnaryOp node
691 </dd>
692 </dl>
693 <a NAME="SimplifyNodeVisitor.__check203" ID="SimplifyNodeVisitor.__check203"></a>
694 <h4>SimplifyNodeVisitor.__check203</h4>
695 <b>__check203</b>(<i>node</i>)
696
697 <p>
698 Private method to check for calls where an unary 'not' is used for
699 an in-check.
700 </p>
701 <dl>
702
703 <dt><i>node</i> (ast.UnaryOp)</dt>
704 <dd>
705 reference to the UnaryOp node
706 </dd>
707 </dl>
708 <a NAME="SimplifyNodeVisitor.__check204" ID="SimplifyNodeVisitor.__check204"></a>
709 <h4>SimplifyNodeVisitor.__check204</h4>
710 <b>__check204</b>(<i>node</i>)
711
712 <p>
713 Private method to check for calls of the type "not (a < b)".
714 </p>
715 <dl>
716
717 <dt><i>node</i> (ast.UnaryOp)</dt>
718 <dd>
719 reference to the UnaryOp node
720 </dd>
721 </dl>
722 <a NAME="SimplifyNodeVisitor.__check205" ID="SimplifyNodeVisitor.__check205"></a>
723 <h4>SimplifyNodeVisitor.__check205</h4>
724 <b>__check205</b>(<i>node</i>)
725
726 <p>
727 Private method to check for calls of the type "not (a <= b)".
728 </p>
729 <dl>
730
731 <dt><i>node</i> (ast.UnaryOp)</dt>
732 <dd>
733 reference to the UnaryOp node
734 </dd>
735 </dl>
736 <a NAME="SimplifyNodeVisitor.__check206" ID="SimplifyNodeVisitor.__check206"></a>
737 <h4>SimplifyNodeVisitor.__check206</h4>
738 <b>__check206</b>(<i>node</i>)
739
740 <p>
741 Private method to check for calls of the type "not (a > b)".
742 </p>
743 <dl>
744
745 <dt><i>node</i> (ast.UnaryOp)</dt>
746 <dd>
747 reference to the UnaryOp node
748 </dd>
749 </dl>
750 <a NAME="SimplifyNodeVisitor.__check207" ID="SimplifyNodeVisitor.__check207"></a>
751 <h4>SimplifyNodeVisitor.__check207</h4>
752 <b>__check207</b>(<i>node</i>)
753
754 <p>
755 Private method to check for calls of the type "not (a >= b)".
756 </p>
757 <dl>
758
759 <dt><i>node</i> (ast.UnaryOp)</dt>
760 <dd>
761 reference to the UnaryOp node
762 </dd>
763 </dl>
764 <a NAME="SimplifyNodeVisitor.__check208" ID="SimplifyNodeVisitor.__check208"></a>
765 <h4>SimplifyNodeVisitor.__check208</h4>
766 <b>__check208</b>(<i>node</i>)
767
768 <p>
769 Private method to check for calls of the type "not (not a)".
770 </p>
771 <dl>
772
773 <dt><i>node</i> (ast.UnaryOp)</dt>
774 <dd>
775 reference to the UnaryOp node
776 </dd>
777 </dl>
778 <a NAME="SimplifyNodeVisitor.__check211" ID="SimplifyNodeVisitor.__check211"></a>
779 <h4>SimplifyNodeVisitor.__check211</h4>
780 <b>__check211</b>(<i>node</i>)
781
782 <p>
783 Private method to check for calls of the type "True if a else False".
784 </p>
785 <dl>
786
787 <dt><i>node</i> (ast.IfExp)</dt>
788 <dd>
789 reference to the AST node to be checked
790 </dd>
791 </dl>
792 <a NAME="SimplifyNodeVisitor.__check212" ID="SimplifyNodeVisitor.__check212"></a>
793 <h4>SimplifyNodeVisitor.__check212</h4>
794 <b>__check212</b>(<i>node</i>)
795
796 <p>
797 Private method to check for calls of the type "False if a else True".
798 </p>
799 <dl>
800
801 <dt><i>node</i> (ast.IfExp)</dt>
802 <dd>
803 reference to the AST node to be checked
804 </dd>
805 </dl>
806 <a NAME="SimplifyNodeVisitor.__check213" ID="SimplifyNodeVisitor.__check213"></a>
807 <h4>SimplifyNodeVisitor.__check213</h4>
808 <b>__check213</b>(<i>node</i>)
809
810 <p>
811 Private method to check for calls of the type "b if not a else a".
812 </p>
813 <dl>
814
815 <dt><i>node</i> (ast.IfExp)</dt>
816 <dd>
817 reference to the AST node to be checked
818 </dd>
819 </dl>
820 <a NAME="SimplifyNodeVisitor.__check221" ID="SimplifyNodeVisitor.__check221"></a>
821 <h4>SimplifyNodeVisitor.__check221</h4>
822 <b>__check221</b>(<i>node</i>)
823
824 <p>
825 Private method to check for calls of the type "a and not a".
826 </p>
827 <dl>
828
829 <dt><i>node</i> (ast.BoolOp)</dt>
830 <dd>
831 reference to the AST node to be checked
832 </dd>
833 </dl>
834 <a NAME="SimplifyNodeVisitor.__check222" ID="SimplifyNodeVisitor.__check222"></a>
835 <h4>SimplifyNodeVisitor.__check222</h4>
836 <b>__check222</b>(<i>node</i>)
837
838 <p>
839 Private method to check for calls of the type "a or not a".
840 </p>
841 <dl>
842
843 <dt><i>node</i> (ast.BoolOp)</dt>
844 <dd>
845 reference to the AST node to be checked
846 </dd>
847 </dl>
848 <a NAME="SimplifyNodeVisitor.__check223" ID="SimplifyNodeVisitor.__check223"></a>
849 <h4>SimplifyNodeVisitor.__check223</h4>
850 <b>__check223</b>(<i>node</i>)
851
852 <p>
853 Private method to check for calls of the type "... or True".
854 </p>
855 <dl>
856
857 <dt><i>node</i> (ast.BoolOp)</dt>
858 <dd>
859 reference to the AST node to be checked
860 </dd>
861 </dl>
862 <a NAME="SimplifyNodeVisitor.__check224" ID="SimplifyNodeVisitor.__check224"></a>
863 <h4>SimplifyNodeVisitor.__check224</h4>
864 <b>__check224</b>(<i>node</i>)
865
866 <p>
867 Private method to check for calls of the type "... and False".
868 </p>
869 <dl>
870
871 <dt><i>node</i> (ast.BoolOp)</dt>
872 <dd>
873 reference to the AST node to be checked
874 </dd>
875 </dl>
876 <a NAME="SimplifyNodeVisitor.__check301" ID="SimplifyNodeVisitor.__check301"></a>
877 <h4>SimplifyNodeVisitor.__check301</h4>
878 <b>__check301</b>(<i>node</i>)
879
880 <p>
881 Private method to check for Yoda conditions.
882 </p>
883 <dl>
884
885 <dt><i>node</i> (ast.Compare)</dt>
886 <dd>
887 reference to the AST node to be checked
888 </dd>
889 </dl>
890 <a NAME="SimplifyNodeVisitor.__check401" ID="SimplifyNodeVisitor.__check401"></a>
891 <h4>SimplifyNodeVisitor.__check401</h4>
892 <b>__check401</b>(<i>node</i>)
893
894 <p>
895 Private method to check for bare boolean function arguments.
896 </p>
897 <dl>
898
899 <dt><i>node</i> (ast.Call)</dt>
900 <dd>
901 reference to the AST node to be checked
902 </dd>
903 </dl>
904 <a NAME="SimplifyNodeVisitor.__check402" ID="SimplifyNodeVisitor.__check402"></a>
905 <h4>SimplifyNodeVisitor.__check402</h4>
906 <b>__check402</b>(<i>node</i>)
907
908 <p>
909 Private method to check for bare numeric function arguments.
910 </p>
911 <dl>
912
913 <dt><i>node</i> (ast.Call)</dt>
914 <dd>
915 reference to the AST node to be checked
916 </dd>
917 </dl>
918 <a NAME="SimplifyNodeVisitor.__getDuplicatedIsinstanceCall" ID="SimplifyNodeVisitor.__getDuplicatedIsinstanceCall"></a>
919 <h4>SimplifyNodeVisitor.__getDuplicatedIsinstanceCall</h4>
920 <b>__getDuplicatedIsinstanceCall</b>(<i>node</i>)
921
922 <p>
923 Private method to get a list of isinstance arguments which could
924 be combined.
925 </p>
926 <dl>
927
928 <dt><i>node</i> (ast.BoolOp)</dt>
929 <dd>
930 reference to the AST node to be inspected
931 </dd>
932 </dl>
933 <dl>
934 <dt>Return:</dt>
935 <dd>
936 list of variable names of duplicated isinstance calls
937 </dd>
938 </dl>
939 <dl>
940 <dt>Return Type:</dt>
941 <dd>
942 list of str
943 </dd>
944 </dl>
945 <a NAME="SimplifyNodeVisitor.__getIfBodyPairs" ID="SimplifyNodeVisitor.__getIfBodyPairs"></a>
946 <h4>SimplifyNodeVisitor.__getIfBodyPairs</h4>
947 <b>__getIfBodyPairs</b>(<i>node</i>)
948
949 <p>
950 Private method to extract a list of pairs of test and body for an
951 If node.
952 </p>
953 <dl>
954
955 <dt><i>node</i> (ast.If)</dt>
956 <dd>
957 reference to the If node to be processed
958 </dd>
959 </dl>
960 <dl>
961 <dt>Return:</dt>
962 <dd>
963 list of pairs of test and body
964 </dd>
965 </dl>
966 <dl>
967 <dt>Return Type:</dt>
968 <dd>
969 list of tuples of (ast.expr, [ast.stmt])
970 </dd>
971 </dl>
972 <a NAME="SimplifyNodeVisitor.__isConstantIncrease" ID="SimplifyNodeVisitor.__isConstantIncrease"></a>
973 <h4>SimplifyNodeVisitor.__isConstantIncrease</h4>
974 <b>__isConstantIncrease</b>(<i>expression</i>)
975
976 <p>
977 Private method check the given expression for being a constant
978 increase.
979 </p>
980 <dl>
981
982 <dt><i>expression</i> (ast.AugAssign)</dt>
983 <dd>
984 reference to the expression node
985 </dd>
986 </dl>
987 <dl>
988 <dt>Return:</dt>
989 <dd>
990 flag indicating a constant increase
991 </dd>
992 </dl>
993 <dl>
994 <dt>Return Type:</dt>
995 <dd>
996 bool
997 </dd>
998 </dl>
999 <a NAME="SimplifyNodeVisitor.__isExceptionCheck" ID="SimplifyNodeVisitor.__isExceptionCheck"></a>
1000 <h4>SimplifyNodeVisitor.__isExceptionCheck</h4>
1001 <b>__isExceptionCheck</b>(<i>node</i>)
1002
1003 <p>
1004 Private method to check, if the node is checking an exception.
1005 </p>
1006 <dl>
1007
1008 <dt><i>node</i> (ast.If)</dt>
1009 <dd>
1010 reference to the node to be checked
1011 </dd>
1012 </dl>
1013 <dl>
1014 <dt>Return:</dt>
1015 <dd>
1016 flag indicating an exception check
1017 </dd>
1018 </dl>
1019 <dl>
1020 <dt>Return Type:</dt>
1021 <dd>
1022 bool
1023 </dd>
1024 </dl>
1025 <a NAME="SimplifyNodeVisitor.__isSameBody" ID="SimplifyNodeVisitor.__isSameBody"></a>
1026 <h4>SimplifyNodeVisitor.__isSameBody</h4>
1027 <b>__isSameBody</b>(<i>body1, body2</i>)
1028
1029 <p>
1030 Private method check, if the given bodies are equivalent.
1031 </p>
1032 <dl>
1033
1034 <dt><i>body1</i> (list of ast.stmt)</dt>
1035 <dd>
1036 list of statements of the first body
1037 </dd>
1038 <dt><i>body2</i> (list of ast.stmt)</dt>
1039 <dd>
1040 list of statements of the second body
1041 </dd>
1042 </dl>
1043 <dl>
1044 <dt>Return:</dt>
1045 <dd>
1046 flag indicating identical bodies
1047 </dd>
1048 </dl>
1049 <dl>
1050 <dt>Return Type:</dt>
1051 <dd>
1052 bool
1053 </dd>
1054 </dl>
1055 <a NAME="SimplifyNodeVisitor.__isSameExpression" ID="SimplifyNodeVisitor.__isSameExpression"></a>
1056 <h4>SimplifyNodeVisitor.__isSameExpression</h4>
1057 <b>__isSameExpression</b>(<i>a, b</i>)
1058
1059 <p>
1060 Private method to check, if two expressions are equal.
1061 </p>
1062 <dl>
1063
1064 <dt><i>a</i> (ast.expr)</dt>
1065 <dd>
1066 first expression to be checked
1067 </dd>
1068 <dt><i>b</i> (ast.expr)</dt>
1069 <dd>
1070 second expression to be checked
1071 </dd>
1072 </dl>
1073 <dl>
1074 <dt>Return:</dt>
1075 <dd>
1076 flag indicating equal expressions
1077 </dd>
1078 </dl>
1079 <dl>
1080 <dt>Return Type:</dt>
1081 <dd>
1082 bool
1083 </dd>
1084 </dl>
1085 <a NAME="SimplifyNodeVisitor.__isStatementEqual" ID="SimplifyNodeVisitor.__isStatementEqual"></a>
1086 <h4>SimplifyNodeVisitor.__isStatementEqual</h4>
1087 <b>__isStatementEqual</b>(<i>a, b</i>)
1088
1089 <p>
1090 Private method to check, if two statements are equal.
1091 </p>
1092 <dl>
1093
1094 <dt><i>a</i> (ast.stmt)</dt>
1095 <dd>
1096 reference to the first statement
1097 </dd>
1098 <dt><i>b</i> (ast.stmt)</dt>
1099 <dd>
1100 reference to the second statement
1101 </dd>
1102 </dl>
1103 <dl>
1104 <dt>Return:</dt>
1105 <dd>
1106 flag indicating if the two statements are equal
1107 </dd>
1108 </dl>
1109 <dl>
1110 <dt>Return Type:</dt>
1111 <dd>
1112 bool
1113 </dd>
1114 </dl>
1115 <a NAME="SimplifyNodeVisitor.__negateTest" ID="SimplifyNodeVisitor.__negateTest"></a>
1116 <h4>SimplifyNodeVisitor.__negateTest</h4>
1117 <b>__negateTest</b>(<i>node</i>)
1118
1119 <p>
1120 Private method negate the given Compare node.
1121 </p>
1122 <dl>
1123
1124 <dt><i>node</i> (ast.Compare)</dt>
1125 <dd>
1126 reference to the node to be negated
1127 </dd>
1128 </dl>
1129 <dl>
1130 <dt>Return:</dt>
1131 <dd>
1132 node with negated logic
1133 </dd>
1134 </dl>
1135 <dl>
1136 <dt>Return Type:</dt>
1137 <dd>
1138 ast.Compare
1139 </dd>
1140 </dl>
1141 <a NAME="SimplifyNodeVisitor.visit_Assign" ID="SimplifyNodeVisitor.visit_Assign"></a>
1142 <h4>SimplifyNodeVisitor.visit_Assign</h4>
1143 <b>visit_Assign</b>(<i>node</i>)
1144
1145 <p>
1146 Public method to process an Assign node.
1147 </p>
1148 <dl>
1149
1150 <dt><i>node</i> (ast.Assign)</dt>
1151 <dd>
1152 reference to the Assign node
1153 </dd>
1154 </dl>
1155 <a NAME="SimplifyNodeVisitor.visit_BoolOp" ID="SimplifyNodeVisitor.visit_BoolOp"></a>
1156 <h4>SimplifyNodeVisitor.visit_BoolOp</h4>
1157 <b>visit_BoolOp</b>(<i>node</i>)
1158
1159 <p>
1160 Public method to process a BoolOp node.
1161 </p>
1162 <dl>
1163
1164 <dt><i>node</i> (ast.BoolOp)</dt>
1165 <dd>
1166 reference to the BoolOp node
1167 </dd>
1168 </dl>
1169 <a NAME="SimplifyNodeVisitor.visit_Call" ID="SimplifyNodeVisitor.visit_Call"></a>
1170 <h4>SimplifyNodeVisitor.visit_Call</h4>
1171 <b>visit_Call</b>(<i>node</i>)
1172
1173 <p>
1174 Public method to process a Call node.
1175 </p>
1176 <dl>
1177
1178 <dt><i>node</i> (ast.Call)</dt>
1179 <dd>
1180 reference to the Call node
1181 </dd>
1182 </dl>
1183 <a NAME="SimplifyNodeVisitor.visit_ClassDef" ID="SimplifyNodeVisitor.visit_ClassDef"></a>
1184 <h4>SimplifyNodeVisitor.visit_ClassDef</h4>
1185 <b>visit_ClassDef</b>(<i>node</i>)
1186
1187 <p>
1188 Public method to process a ClassDef node.
1189 </p>
1190 <dl>
1191
1192 <dt><i>node</i> (ast.ClassDef)</dt>
1193 <dd>
1194 reference to the ClassDef node
1195 </dd>
1196 </dl>
1197 <a NAME="SimplifyNodeVisitor.visit_Compare" ID="SimplifyNodeVisitor.visit_Compare"></a>
1198 <h4>SimplifyNodeVisitor.visit_Compare</h4>
1199 <b>visit_Compare</b>(<i>node</i>)
1200
1201 <p>
1202 Public method to process a Compare node.
1203 </p>
1204 <dl>
1205
1206 <dt><i>node</i> (ast.Compare)</dt>
1207 <dd>
1208 reference to the Compare node
1209 </dd>
1210 </dl>
1211 <a NAME="SimplifyNodeVisitor.visit_Expr" ID="SimplifyNodeVisitor.visit_Expr"></a>
1212 <h4>SimplifyNodeVisitor.visit_Expr</h4>
1213 <b>visit_Expr</b>(<i>node</i>)
1214
1215 <p>
1216 Public method to process an Expr node.
1217 </p>
1218 <dl>
1219
1220 <dt><i>node</i> (ast.Expr)</dt>
1221 <dd>
1222 reference to the Expr node
1223 </dd>
1224 </dl>
1225 <a NAME="SimplifyNodeVisitor.visit_For" ID="SimplifyNodeVisitor.visit_For"></a>
1226 <h4>SimplifyNodeVisitor.visit_For</h4>
1227 <b>visit_For</b>(<i>node</i>)
1228
1229 <p>
1230 Public method to process a For node.
1231 </p>
1232 <dl>
1233
1234 <dt><i>node</i> (ast.For)</dt>
1235 <dd>
1236 reference to the For node
1237 </dd>
1238 </dl>
1239 <a NAME="SimplifyNodeVisitor.visit_If" ID="SimplifyNodeVisitor.visit_If"></a>
1240 <h4>SimplifyNodeVisitor.visit_If</h4>
1241 <b>visit_If</b>(<i>node</i>)
1242
1243 <p>
1244 Public method to process an If node.
1245 </p>
1246 <dl>
1247
1248 <dt><i>node</i> (ast.If)</dt>
1249 <dd>
1250 reference to the If node
1251 </dd>
1252 </dl>
1253 <a NAME="SimplifyNodeVisitor.visit_IfExp" ID="SimplifyNodeVisitor.visit_IfExp"></a>
1254 <h4>SimplifyNodeVisitor.visit_IfExp</h4>
1255 <b>visit_IfExp</b>(<i>node</i>)
1256
1257 <p>
1258 Public method to process an IfExp node.
1259 </p>
1260 <dl>
1261
1262 <dt><i>node</i> (ast.IfExp)</dt>
1263 <dd>
1264 reference to the IfExp node
1265 </dd>
1266 </dl>
1267 <a NAME="SimplifyNodeVisitor.visit_Try" ID="SimplifyNodeVisitor.visit_Try"></a>
1268 <h4>SimplifyNodeVisitor.visit_Try</h4>
1269 <b>visit_Try</b>(<i>node</i>)
1270
1271 <p>
1272 Public method to process a Try node.
1273 </p>
1274 <dl>
1275
1276 <dt><i>node</i> (ast.Try)</dt>
1277 <dd>
1278 reference to the Try node
1279 </dd>
1280 </dl>
1281 <a NAME="SimplifyNodeVisitor.visit_UnaryOp" ID="SimplifyNodeVisitor.visit_UnaryOp"></a>
1282 <h4>SimplifyNodeVisitor.visit_UnaryOp</h4>
1283 <b>visit_UnaryOp</b>(<i>node</i>)
1284
1285 <p>
1286 Public method to process a UnaryOp node.
1287 </p>
1288 <dl>
1289
1290 <dt><i>node</i> (ast.UnaryOp)</dt>
1291 <dd>
1292 reference to the UnaryOp node
1293 </dd>
1294 </dl>
1295 <a NAME="SimplifyNodeVisitor.visit_With" ID="SimplifyNodeVisitor.visit_With"></a>
1296 <h4>SimplifyNodeVisitor.visit_With</h4>
1297 <b>visit_With</b>(<i>node</i>)
1298
1299 <p>
1300 Public method to process a With node.
1301 </p>
1302 <dl>
1303
1304 <dt><i>node</i> (ast.With)</dt>
1305 <dd>
1306 reference to the With node
1307 </dd>
1308 </dl>
1309 <div align="right"><a href="#top">Up</a></div>
1310 <hr />
1311 </body></html>

eric ide

mercurial