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

changeset 8197
9037d09ed87c
child 8202
df194f43119c
equal deleted inserted replaced
8196:e3a5a84e409f 8197:9037d09ed87c
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric6.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>eric6.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">__check120</a></td>
150 <td>Private method to check for classes that inherit from object.</td>
151 </tr>
152 <tr>
153 <td><a href="#SimplifyNodeVisitor.__check201">__check201</a></td>
154 <td>Private method to check for calls where an unary 'not' is used for an unequality.</td>
155 </tr>
156 <tr>
157 <td><a href="#SimplifyNodeVisitor.__check202">__check202</a></td>
158 <td>Private method to check for calls where an unary 'not' is used for an equality.</td>
159 </tr>
160 <tr>
161 <td><a href="#SimplifyNodeVisitor.__check203">__check203</a></td>
162 <td>Private method to check for calls where an unary 'not' is used for an in-check.</td>
163 </tr>
164 <tr>
165 <td><a href="#SimplifyNodeVisitor.__check204">__check204</a></td>
166 <td>Private method to check for calls of the type "not (a < b)".</td>
167 </tr>
168 <tr>
169 <td><a href="#SimplifyNodeVisitor.__check205">__check205</a></td>
170 <td>Private method to check for calls of the type "not (a <= b)".</td>
171 </tr>
172 <tr>
173 <td><a href="#SimplifyNodeVisitor.__check206">__check206</a></td>
174 <td>Private method to check for calls of the type "not (a > b)".</td>
175 </tr>
176 <tr>
177 <td><a href="#SimplifyNodeVisitor.__check207">__check207</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.__check208">__check208</a></td>
182 <td>Private method to check for calls of the type "not (not a)".</td>
183 </tr>
184 <tr>
185 <td><a href="#SimplifyNodeVisitor.__check211">__check211</a></td>
186 <td>Private method to check for calls of the type "True if a else False".</td>
187 </tr>
188 <tr>
189 <td><a href="#SimplifyNodeVisitor.__check212">__check212</a></td>
190 <td>Private method to check for calls of the type "False if a else True".</td>
191 </tr>
192 <tr>
193 <td><a href="#SimplifyNodeVisitor.__check213">__check213</a></td>
194 <td>Private method to check for calls of the type "b if not a else a".</td>
195 </tr>
196 <tr>
197 <td><a href="#SimplifyNodeVisitor.__check221">__check221</a></td>
198 <td>Private method to check for calls of the type "a and not a".</td>
199 </tr>
200 <tr>
201 <td><a href="#SimplifyNodeVisitor.__check222">__check222</a></td>
202 <td>Private method to check for calls of the type "a or not a".</td>
203 </tr>
204 <tr>
205 <td><a href="#SimplifyNodeVisitor.__check223">__check223</a></td>
206 <td>Private method to check for calls of the type "...</td>
207 </tr>
208 <tr>
209 <td><a href="#SimplifyNodeVisitor.__check224">__check224</a></td>
210 <td>Private method to check for calls of the type "...</td>
211 </tr>
212 <tr>
213 <td><a href="#SimplifyNodeVisitor.__check301">__check301</a></td>
214 <td>Private method to check for Yoda conditions.</td>
215 </tr>
216 <tr>
217 <td><a href="#SimplifyNodeVisitor.__getDuplicatedIsinstanceCall">__getDuplicatedIsinstanceCall</a></td>
218 <td>Private method to get a list of isinstance arguments which could be combined.</td>
219 </tr>
220 <tr>
221 <td><a href="#SimplifyNodeVisitor.__getIfBodyPairs">__getIfBodyPairs</a></td>
222 <td>Private method to extract a list of pairs of test and body for an If node.</td>
223 </tr>
224 <tr>
225 <td><a href="#SimplifyNodeVisitor.__isConstantIncrease">__isConstantIncrease</a></td>
226 <td>Private method check the given expression for being a constant increase.</td>
227 </tr>
228 <tr>
229 <td><a href="#SimplifyNodeVisitor.__isExceptionCheck">__isExceptionCheck</a></td>
230 <td>Private method to check, if the node is checking an exception.</td>
231 </tr>
232 <tr>
233 <td><a href="#SimplifyNodeVisitor.__isSameBody">__isSameBody</a></td>
234 <td>Private method check, if the given bodies are equivalent.</td>
235 </tr>
236 <tr>
237 <td><a href="#SimplifyNodeVisitor.__isSameExpression">__isSameExpression</a></td>
238 <td>Private method to check, if two expressions are equal.</td>
239 </tr>
240 <tr>
241 <td><a href="#SimplifyNodeVisitor.__isStatementEqual">__isStatementEqual</a></td>
242 <td>Private method to check, if two statements are equal.</td>
243 </tr>
244 <tr>
245 <td><a href="#SimplifyNodeVisitor.__negateTest">__negateTest</a></td>
246 <td>Private method negate the given Compare node.</td>
247 </tr>
248 <tr>
249 <td><a href="#SimplifyNodeVisitor.visit_BoolOp">visit_BoolOp</a></td>
250 <td>Public method to process a BoolOp node.</td>
251 </tr>
252 <tr>
253 <td><a href="#SimplifyNodeVisitor.visit_Call">visit_Call</a></td>
254 <td>Public method to process a Call node.</td>
255 </tr>
256 <tr>
257 <td><a href="#SimplifyNodeVisitor.visit_ClassDef">visit_ClassDef</a></td>
258 <td>Public method to process a ClassDef node.</td>
259 </tr>
260 <tr>
261 <td><a href="#SimplifyNodeVisitor.visit_Compare">visit_Compare</a></td>
262 <td>Public method to process a Compare node.</td>
263 </tr>
264 <tr>
265 <td><a href="#SimplifyNodeVisitor.visit_Expr">visit_Expr</a></td>
266 <td>Public method to process an Expr node.</td>
267 </tr>
268 <tr>
269 <td><a href="#SimplifyNodeVisitor.visit_For">visit_For</a></td>
270 <td>Public method to process a For node.</td>
271 </tr>
272 <tr>
273 <td><a href="#SimplifyNodeVisitor.visit_If">visit_If</a></td>
274 <td>Public method to process an If node.</td>
275 </tr>
276 <tr>
277 <td><a href="#SimplifyNodeVisitor.visit_IfExp">visit_IfExp</a></td>
278 <td>Public method to process an IfExp node.</td>
279 </tr>
280 <tr>
281 <td><a href="#SimplifyNodeVisitor.visit_Try">visit_Try</a></td>
282 <td>Public method to process a Try node.</td>
283 </tr>
284 <tr>
285 <td><a href="#SimplifyNodeVisitor.visit_UnaryOp">visit_UnaryOp</a></td>
286 <td>Public method to process a UnaryOp node.</td>
287 </tr>
288 <tr>
289 <td><a href="#SimplifyNodeVisitor.visit_With">visit_With</a></td>
290 <td>Public method to process a With node.</td>
291 </tr>
292 </table>
293 <h3>Static Methods</h3>
294
295 <table>
296 <tr><td>None</td></tr>
297 </table>
298
299 <a NAME="SimplifyNodeVisitor.__init__" ID="SimplifyNodeVisitor.__init__"></a>
300 <h4>SimplifyNodeVisitor (Constructor)</h4>
301 <b>SimplifyNodeVisitor</b>(<i>errorCallback</i>)
302
303 <p>
304 Constructor
305 </p>
306 <dl>
307
308 <dt><i>errorCallback</i> (func)</dt>
309 <dd>
310 callback function to register an error
311 </dd>
312 </dl>
313 <a NAME="SimplifyNodeVisitor.__check101" ID="SimplifyNodeVisitor.__check101"></a>
314 <h4>SimplifyNodeVisitor.__check101</h4>
315 <b>__check101</b>(<i>node</i>)
316
317 <p>
318 Private method to check for duplicate isinstance() calls.
319 </p>
320 <dl>
321
322 <dt><i>node</i> (ast.BoolOp)</dt>
323 <dd>
324 reference to the AST node to be checked
325 </dd>
326 </dl>
327 <a NAME="SimplifyNodeVisitor.__check102" ID="SimplifyNodeVisitor.__check102"></a>
328 <h4>SimplifyNodeVisitor.__check102</h4>
329 <b>__check102</b>(<i>node</i>)
330
331 <p>
332 Private method to check for nested if statements without else blocks.
333 </p>
334 <dl>
335
336 <dt><i>node</i> (ast.If)</dt>
337 <dd>
338 reference to the AST node to be checked
339 </dd>
340 </dl>
341 <a NAME="SimplifyNodeVisitor.__check103" ID="SimplifyNodeVisitor.__check103"></a>
342 <h4>SimplifyNodeVisitor.__check103</h4>
343 <b>__check103</b>(<i>node</i>)
344
345 <p>
346 Private method to check for calls that wrap a condition to return
347 a bool.
348 </p>
349 <dl>
350
351 <dt><i>node</i> (ast.If)</dt>
352 <dd>
353 reference to the AST node to be checked
354 </dd>
355 </dl>
356 <a NAME="SimplifyNodeVisitor.__check104" ID="SimplifyNodeVisitor.__check104"></a>
357 <h4>SimplifyNodeVisitor.__check104</h4>
358 <b>__check104</b>(<i>node</i>)
359
360 <p>
361 Private method to check for "iterate and yield" patterns.
362 </p>
363 <dl>
364
365 <dt><i>node</i> (ast.For)</dt>
366 <dd>
367 reference to the AST node to be checked
368 </dd>
369 </dl>
370 <a NAME="SimplifyNodeVisitor.__check105" ID="SimplifyNodeVisitor.__check105"></a>
371 <h4>SimplifyNodeVisitor.__check105</h4>
372 <b>__check105</b>(<i>node</i>)
373
374 <p>
375 Private method to check for "try-except-pass" patterns.
376 </p>
377 <dl>
378
379 <dt><i>node</i> (ast.Try)</dt>
380 <dd>
381 reference to the AST node to be checked
382 </dd>
383 </dl>
384 <a NAME="SimplifyNodeVisitor.__check106" ID="SimplifyNodeVisitor.__check106"></a>
385 <h4>SimplifyNodeVisitor.__check106</h4>
386 <b>__check106</b>(<i>node</i>)
387
388 <p>
389 Private method to check for calls where an exception is raised in else.
390 </p>
391 <dl>
392
393 <dt><i>node</i> (ast.If)</dt>
394 <dd>
395 reference to the AST node to be checked
396 </dd>
397 </dl>
398 <a NAME="SimplifyNodeVisitor.__check107" ID="SimplifyNodeVisitor.__check107"></a>
399 <h4>SimplifyNodeVisitor.__check107</h4>
400 <b>__check107</b>(<i>node</i>)
401
402 <p>
403 Private method to check for calls where try/except and finally have
404 'return'.
405 </p>
406 <dl>
407
408 <dt><i>node</i> (ast.Try)</dt>
409 <dd>
410 reference to the AST node to be checked
411 </dd>
412 </dl>
413 <a NAME="SimplifyNodeVisitor.__check108" ID="SimplifyNodeVisitor.__check108"></a>
414 <h4>SimplifyNodeVisitor.__check108</h4>
415 <b>__check108</b>(<i>node</i>)
416
417 <p>
418 Private method to check for if-elses which could be a ternary
419 operator assignment.
420 </p>
421 <dl>
422
423 <dt><i>node</i> (ast.If)</dt>
424 <dd>
425 reference to the AST node to be checked
426 </dd>
427 </dl>
428 <a NAME="SimplifyNodeVisitor.__check109" ID="SimplifyNodeVisitor.__check109"></a>
429 <h4>SimplifyNodeVisitor.__check109</h4>
430 <b>__check109</b>(<i>node</i>)
431
432 <p>
433 Private method to check for multiple equalities with the same value
434 are combined via "or".
435 </p>
436 <dl>
437
438 <dt><i>node</i> (ast.BoolOp)</dt>
439 <dd>
440 reference to the AST node to be checked
441 </dd>
442 </dl>
443 <a NAME="SimplifyNodeVisitor.__check110_111" ID="SimplifyNodeVisitor.__check110_111"></a>
444 <h4>SimplifyNodeVisitor.__check110_111</h4>
445 <b>__check110_111</b>(<i>node</i>)
446
447 <p>
448 Private method to check if any / all could be used.
449 </p>
450 <dl>
451
452 <dt><i>node</i> (ast.For)</dt>
453 <dd>
454 reference to the AST node to be checked
455 </dd>
456 </dl>
457 <a NAME="SimplifyNodeVisitor.__check112" ID="SimplifyNodeVisitor.__check112"></a>
458 <h4>SimplifyNodeVisitor.__check112</h4>
459 <b>__check112</b>(<i>node</i>)
460
461 <p>
462 Private method to check for non-capitalized calls to environment
463 variables.
464 </p>
465 <dl>
466
467 <dt><i>node</i> (ast.Expr)</dt>
468 <dd>
469 reference to the AST node to be checked
470 </dd>
471 </dl>
472 <a NAME="SimplifyNodeVisitor.__check113" ID="SimplifyNodeVisitor.__check113"></a>
473 <h4>SimplifyNodeVisitor.__check113</h4>
474 <b>__check113</b>(<i>node</i>)
475
476 <p>
477 Private method to check for loops in which "enumerate" should be
478 used.
479 </p>
480 <dl>
481
482 <dt><i>node</i> (ast.For)</dt>
483 <dd>
484 reference to the AST node to be checked
485 </dd>
486 </dl>
487 <a NAME="SimplifyNodeVisitor.__check114" ID="SimplifyNodeVisitor.__check114"></a>
488 <h4>SimplifyNodeVisitor.__check114</h4>
489 <b>__check114</b>(<i>node</i>)
490
491 <p>
492 Private method to check for alternative if clauses with identical
493 bodies.
494 </p>
495 <dl>
496
497 <dt><i>node</i> (ast.If)</dt>
498 <dd>
499 reference to the AST node to be checked
500 </dd>
501 </dl>
502 <a NAME="SimplifyNodeVisitor.__check115" ID="SimplifyNodeVisitor.__check115"></a>
503 <h4>SimplifyNodeVisitor.__check115</h4>
504 <b>__check115</b>(<i>node</i>)
505
506 <p>
507 Private method to to check for places where open() is called without
508 a context handler.
509 </p>
510 <dl>
511
512 <dt><i>node</i> (ast.Call)</dt>
513 <dd>
514 reference to the AST node to be checked
515 </dd>
516 </dl>
517 <a NAME="SimplifyNodeVisitor.__check116" ID="SimplifyNodeVisitor.__check116"></a>
518 <h4>SimplifyNodeVisitor.__check116</h4>
519 <b>__check116</b>(<i>node</i>)
520
521 <p>
522 Private method to check for places with 3 or more consecutive
523 if-statements with direct returns.
524 </p>
525 <p>
526 * Each if-statement must be a check for equality with the
527 same variable
528 * Each if-statement must just have a "return"
529 * Else must also just have a return
530 </p>
531 <dl>
532
533 <dt><i>node</i> (ast.If)</dt>
534 <dd>
535 reference to the AST node to be checked
536 </dd>
537 </dl>
538 <a NAME="SimplifyNodeVisitor.__check117" ID="SimplifyNodeVisitor.__check117"></a>
539 <h4>SimplifyNodeVisitor.__check117</h4>
540 <b>__check117</b>(<i>node</i>)
541
542 <p>
543 Private method to check for multiple with-statements with same scope.
544 </p>
545 <dl>
546
547 <dt><i>node</i> (ast.With)</dt>
548 <dd>
549 reference to the AST node to be checked
550 </dd>
551 </dl>
552 <a NAME="SimplifyNodeVisitor.__check118" ID="SimplifyNodeVisitor.__check118"></a>
553 <h4>SimplifyNodeVisitor.__check118</h4>
554 <b>__check118</b>(<i>node</i>)
555
556 <p>
557 Private method to check for usages of "key in dict.keys()".
558 </p>
559 <dl>
560
561 <dt><i>node</i> (ast.Compare or ast.For)</dt>
562 <dd>
563 reference to the AST node to be checked
564 </dd>
565 </dl>
566 <a NAME="SimplifyNodeVisitor.__check119" ID="SimplifyNodeVisitor.__check119"></a>
567 <h4>SimplifyNodeVisitor.__check119</h4>
568 <b>__check119</b>(<i>node</i>)
569
570 <p>
571 Private method to check for classes that should be "dataclasses".
572 </p>
573 <dl>
574
575 <dt><i>node</i> (ast.ClassDef)</dt>
576 <dd>
577 reference to the AST node to be checked
578 </dd>
579 </dl>
580 <a NAME="SimplifyNodeVisitor.__check120" ID="SimplifyNodeVisitor.__check120"></a>
581 <h4>SimplifyNodeVisitor.__check120</h4>
582 <b>__check120</b>(<i>node</i>)
583
584 <p>
585 Private method to check for classes that inherit from object.
586 </p>
587 <dl>
588
589 <dt><i>node</i> (ast.ClassDef)</dt>
590 <dd>
591 reference to the AST node to be checked
592 </dd>
593 </dl>
594 <a NAME="SimplifyNodeVisitor.__check201" ID="SimplifyNodeVisitor.__check201"></a>
595 <h4>SimplifyNodeVisitor.__check201</h4>
596 <b>__check201</b>(<i>node</i>)
597
598 <p>
599 Private method to check for calls where an unary 'not' is used for
600 an unequality.
601 </p>
602 <dl>
603
604 <dt><i>node</i> (ast.UnaryOp)</dt>
605 <dd>
606 reference to the UnaryOp node
607 </dd>
608 </dl>
609 <a NAME="SimplifyNodeVisitor.__check202" ID="SimplifyNodeVisitor.__check202"></a>
610 <h4>SimplifyNodeVisitor.__check202</h4>
611 <b>__check202</b>(<i>node</i>)
612
613 <p>
614 Private method to check for calls where an unary 'not' is used for
615 an equality.
616 </p>
617 <dl>
618
619 <dt><i>node</i> (ast.UnaryOp)</dt>
620 <dd>
621 reference to the UnaryOp node
622 </dd>
623 </dl>
624 <a NAME="SimplifyNodeVisitor.__check203" ID="SimplifyNodeVisitor.__check203"></a>
625 <h4>SimplifyNodeVisitor.__check203</h4>
626 <b>__check203</b>(<i>node</i>)
627
628 <p>
629 Private method to check for calls where an unary 'not' is used for
630 an in-check.
631 </p>
632 <dl>
633
634 <dt><i>node</i> (ast.UnaryOp)</dt>
635 <dd>
636 reference to the UnaryOp node
637 </dd>
638 </dl>
639 <a NAME="SimplifyNodeVisitor.__check204" ID="SimplifyNodeVisitor.__check204"></a>
640 <h4>SimplifyNodeVisitor.__check204</h4>
641 <b>__check204</b>(<i>node</i>)
642
643 <p>
644 Private method to check for calls of the type "not (a < b)".
645 </p>
646 <dl>
647
648 <dt><i>node</i> (ast.UnaryOp)</dt>
649 <dd>
650 reference to the UnaryOp node
651 </dd>
652 </dl>
653 <a NAME="SimplifyNodeVisitor.__check205" ID="SimplifyNodeVisitor.__check205"></a>
654 <h4>SimplifyNodeVisitor.__check205</h4>
655 <b>__check205</b>(<i>node</i>)
656
657 <p>
658 Private method to check for calls of the type "not (a <= b)".
659 </p>
660 <dl>
661
662 <dt><i>node</i> (ast.UnaryOp)</dt>
663 <dd>
664 reference to the UnaryOp node
665 </dd>
666 </dl>
667 <a NAME="SimplifyNodeVisitor.__check206" ID="SimplifyNodeVisitor.__check206"></a>
668 <h4>SimplifyNodeVisitor.__check206</h4>
669 <b>__check206</b>(<i>node</i>)
670
671 <p>
672 Private method to check for calls of the type "not (a > b)".
673 </p>
674 <dl>
675
676 <dt><i>node</i> (ast.UnaryOp)</dt>
677 <dd>
678 reference to the UnaryOp node
679 </dd>
680 </dl>
681 <a NAME="SimplifyNodeVisitor.__check207" ID="SimplifyNodeVisitor.__check207"></a>
682 <h4>SimplifyNodeVisitor.__check207</h4>
683 <b>__check207</b>(<i>node</i>)
684
685 <p>
686 Private method to check for calls of the type "not (a >= b)".
687 </p>
688 <dl>
689
690 <dt><i>node</i> (ast.UnaryOp)</dt>
691 <dd>
692 reference to the UnaryOp node
693 </dd>
694 </dl>
695 <a NAME="SimplifyNodeVisitor.__check208" ID="SimplifyNodeVisitor.__check208"></a>
696 <h4>SimplifyNodeVisitor.__check208</h4>
697 <b>__check208</b>(<i>node</i>)
698
699 <p>
700 Private method to check for calls of the type "not (not a)".
701 </p>
702 <dl>
703
704 <dt><i>node</i> (ast.UnaryOp)</dt>
705 <dd>
706 reference to the UnaryOp node
707 </dd>
708 </dl>
709 <a NAME="SimplifyNodeVisitor.__check211" ID="SimplifyNodeVisitor.__check211"></a>
710 <h4>SimplifyNodeVisitor.__check211</h4>
711 <b>__check211</b>(<i>node</i>)
712
713 <p>
714 Private method to check for calls of the type "True if a else False".
715 </p>
716 <dl>
717
718 <dt><i>node</i> (ast.IfExp)</dt>
719 <dd>
720 reference to the AST node to be checked
721 </dd>
722 </dl>
723 <a NAME="SimplifyNodeVisitor.__check212" ID="SimplifyNodeVisitor.__check212"></a>
724 <h4>SimplifyNodeVisitor.__check212</h4>
725 <b>__check212</b>(<i>node</i>)
726
727 <p>
728 Private method to check for calls of the type "False if a else True".
729 </p>
730 <dl>
731
732 <dt><i>node</i> (ast.IfExp)</dt>
733 <dd>
734 reference to the AST node to be checked
735 </dd>
736 </dl>
737 <a NAME="SimplifyNodeVisitor.__check213" ID="SimplifyNodeVisitor.__check213"></a>
738 <h4>SimplifyNodeVisitor.__check213</h4>
739 <b>__check213</b>(<i>node</i>)
740
741 <p>
742 Private method to check for calls of the type "b if not a else a".
743 </p>
744 <dl>
745
746 <dt><i>node</i> (ast.IfExp)</dt>
747 <dd>
748 reference to the AST node to be checked
749 </dd>
750 </dl>
751 <a NAME="SimplifyNodeVisitor.__check221" ID="SimplifyNodeVisitor.__check221"></a>
752 <h4>SimplifyNodeVisitor.__check221</h4>
753 <b>__check221</b>(<i>node</i>)
754
755 <p>
756 Private method to check for calls of the type "a and not a".
757 </p>
758 <dl>
759
760 <dt><i>node</i> (ast.BoolOp)</dt>
761 <dd>
762 reference to the AST node to be checked
763 </dd>
764 </dl>
765 <a NAME="SimplifyNodeVisitor.__check222" ID="SimplifyNodeVisitor.__check222"></a>
766 <h4>SimplifyNodeVisitor.__check222</h4>
767 <b>__check222</b>(<i>node</i>)
768
769 <p>
770 Private method to check for calls of the type "a or not a".
771 </p>
772 <dl>
773
774 <dt><i>node</i> (ast.BoolOp)</dt>
775 <dd>
776 reference to the AST node to be checked
777 </dd>
778 </dl>
779 <a NAME="SimplifyNodeVisitor.__check223" ID="SimplifyNodeVisitor.__check223"></a>
780 <h4>SimplifyNodeVisitor.__check223</h4>
781 <b>__check223</b>(<i>node</i>)
782
783 <p>
784 Private method to check for calls of the type "... or True".
785 </p>
786 <dl>
787
788 <dt><i>node</i> (ast.BoolOp)</dt>
789 <dd>
790 reference to the AST node to be checked
791 </dd>
792 </dl>
793 <a NAME="SimplifyNodeVisitor.__check224" ID="SimplifyNodeVisitor.__check224"></a>
794 <h4>SimplifyNodeVisitor.__check224</h4>
795 <b>__check224</b>(<i>node</i>)
796
797 <p>
798 Private method to check for calls of the type "... and False".
799 </p>
800 <dl>
801
802 <dt><i>node</i> (ast.BoolOp)</dt>
803 <dd>
804 reference to the AST node to be checked
805 </dd>
806 </dl>
807 <a NAME="SimplifyNodeVisitor.__check301" ID="SimplifyNodeVisitor.__check301"></a>
808 <h4>SimplifyNodeVisitor.__check301</h4>
809 <b>__check301</b>(<i>node</i>)
810
811 <p>
812 Private method to check for Yoda conditions.
813 </p>
814 <dl>
815
816 <dt><i>node</i> (ast.Compare)</dt>
817 <dd>
818 reference to the AST node to be checked
819 </dd>
820 </dl>
821 <a NAME="SimplifyNodeVisitor.__getDuplicatedIsinstanceCall" ID="SimplifyNodeVisitor.__getDuplicatedIsinstanceCall"></a>
822 <h4>SimplifyNodeVisitor.__getDuplicatedIsinstanceCall</h4>
823 <b>__getDuplicatedIsinstanceCall</b>(<i>node</i>)
824
825 <p>
826 Private method to get a list of isinstance arguments which could
827 be combined.
828 </p>
829 <dl>
830
831 <dt><i>node</i> (ast.BoolOp)</dt>
832 <dd>
833 reference to the AST node to be inspected
834 </dd>
835 </dl>
836 <dl>
837 <dt>Return:</dt>
838 <dd>
839 list of variable names of duplicated isinstance calls
840 </dd>
841 </dl>
842 <dl>
843 <dt>Return Type:</dt>
844 <dd>
845 list of str
846 </dd>
847 </dl>
848 <a NAME="SimplifyNodeVisitor.__getIfBodyPairs" ID="SimplifyNodeVisitor.__getIfBodyPairs"></a>
849 <h4>SimplifyNodeVisitor.__getIfBodyPairs</h4>
850 <b>__getIfBodyPairs</b>(<i>node</i>)
851
852 <p>
853 Private method to extract a list of pairs of test and body for an
854 If node.
855 </p>
856 <dl>
857
858 <dt><i>node</i> (ast.If)</dt>
859 <dd>
860 reference to the If node to be processed
861 </dd>
862 </dl>
863 <dl>
864 <dt>Return:</dt>
865 <dd>
866 list of pairs of test and body
867 </dd>
868 </dl>
869 <dl>
870 <dt>Return Type:</dt>
871 <dd>
872 list of tuples of (ast.expr, [ast.stmt])
873 </dd>
874 </dl>
875 <a NAME="SimplifyNodeVisitor.__isConstantIncrease" ID="SimplifyNodeVisitor.__isConstantIncrease"></a>
876 <h4>SimplifyNodeVisitor.__isConstantIncrease</h4>
877 <b>__isConstantIncrease</b>(<i>expression</i>)
878
879 <p>
880 Private method check the given expression for being a constant
881 increase.
882 </p>
883 <dl>
884
885 <dt><i>expression</i> (ast.AugAssign)</dt>
886 <dd>
887 reference to the expression node
888 </dd>
889 </dl>
890 <dl>
891 <dt>Return:</dt>
892 <dd>
893 flag indicating a constant increase
894 </dd>
895 </dl>
896 <dl>
897 <dt>Return Type:</dt>
898 <dd>
899 bool
900 </dd>
901 </dl>
902 <a NAME="SimplifyNodeVisitor.__isExceptionCheck" ID="SimplifyNodeVisitor.__isExceptionCheck"></a>
903 <h4>SimplifyNodeVisitor.__isExceptionCheck</h4>
904 <b>__isExceptionCheck</b>(<i>node</i>)
905
906 <p>
907 Private method to check, if the node is checking an exception.
908 </p>
909 <dl>
910
911 <dt><i>node</i> (ast.If)</dt>
912 <dd>
913 reference to the node to be checked
914 </dd>
915 </dl>
916 <dl>
917 <dt>Return:</dt>
918 <dd>
919 flag indicating an exception check
920 </dd>
921 </dl>
922 <dl>
923 <dt>Return Type:</dt>
924 <dd>
925 bool
926 </dd>
927 </dl>
928 <a NAME="SimplifyNodeVisitor.__isSameBody" ID="SimplifyNodeVisitor.__isSameBody"></a>
929 <h4>SimplifyNodeVisitor.__isSameBody</h4>
930 <b>__isSameBody</b>(<i>body1, body2</i>)
931
932 <p>
933 Private method check, if the given bodies are equivalent.
934 </p>
935 <dl>
936
937 <dt><i>body1</i> (list of ast.stmt)</dt>
938 <dd>
939 list of statements of the first body
940 </dd>
941 <dt><i>body2</i> (list of ast.stmt)</dt>
942 <dd>
943 list of statements of the second body
944 </dd>
945 </dl>
946 <dl>
947 <dt>Return:</dt>
948 <dd>
949 flag indicating identical bodies
950 </dd>
951 </dl>
952 <dl>
953 <dt>Return Type:</dt>
954 <dd>
955 bool
956 </dd>
957 </dl>
958 <a NAME="SimplifyNodeVisitor.__isSameExpression" ID="SimplifyNodeVisitor.__isSameExpression"></a>
959 <h4>SimplifyNodeVisitor.__isSameExpression</h4>
960 <b>__isSameExpression</b>(<i>a, b</i>)
961
962 <p>
963 Private method to check, if two expressions are equal.
964 </p>
965 <dl>
966
967 <dt><i>a</i> (ast.expr)</dt>
968 <dd>
969 first expression to be checked
970 </dd>
971 <dt><i>b</i> (ast.expr)</dt>
972 <dd>
973 second expression to be checked
974 </dd>
975 </dl>
976 <dl>
977 <dt>Return:</dt>
978 <dd>
979 flag indicating equal expressions
980 </dd>
981 </dl>
982 <dl>
983 <dt>Return Type:</dt>
984 <dd>
985 bool
986 </dd>
987 </dl>
988 <a NAME="SimplifyNodeVisitor.__isStatementEqual" ID="SimplifyNodeVisitor.__isStatementEqual"></a>
989 <h4>SimplifyNodeVisitor.__isStatementEqual</h4>
990 <b>__isStatementEqual</b>(<i>a, b</i>)
991
992 <p>
993 Private method to check, if two statements are equal.
994 </p>
995 <dl>
996
997 <dt><i>a</i> (ast.stmt)</dt>
998 <dd>
999 reference to the first statement
1000 </dd>
1001 <dt><i>b</i> (ast.stmt)</dt>
1002 <dd>
1003 reference to the second statement
1004 </dd>
1005 </dl>
1006 <dl>
1007 <dt>Return:</dt>
1008 <dd>
1009 flag indicating if the two statements are equal
1010 </dd>
1011 </dl>
1012 <dl>
1013 <dt>Return Type:</dt>
1014 <dd>
1015 bool
1016 </dd>
1017 </dl>
1018 <a NAME="SimplifyNodeVisitor.__negateTest" ID="SimplifyNodeVisitor.__negateTest"></a>
1019 <h4>SimplifyNodeVisitor.__negateTest</h4>
1020 <b>__negateTest</b>(<i>node</i>)
1021
1022 <p>
1023 Private method negate the given Compare node.
1024 </p>
1025 <dl>
1026
1027 <dt><i>node</i> (ast.Compare)</dt>
1028 <dd>
1029 reference to the node to be negated
1030 </dd>
1031 </dl>
1032 <dl>
1033 <dt>Return:</dt>
1034 <dd>
1035 node with negated logic
1036 </dd>
1037 </dl>
1038 <dl>
1039 <dt>Return Type:</dt>
1040 <dd>
1041 ast.Compare
1042 </dd>
1043 </dl>
1044 <a NAME="SimplifyNodeVisitor.visit_BoolOp" ID="SimplifyNodeVisitor.visit_BoolOp"></a>
1045 <h4>SimplifyNodeVisitor.visit_BoolOp</h4>
1046 <b>visit_BoolOp</b>(<i>node</i>)
1047
1048 <p>
1049 Public method to process a BoolOp node.
1050 </p>
1051 <dl>
1052
1053 <dt><i>node</i> (ast.BoolOp)</dt>
1054 <dd>
1055 reference to the BoolOp node
1056 </dd>
1057 </dl>
1058 <a NAME="SimplifyNodeVisitor.visit_Call" ID="SimplifyNodeVisitor.visit_Call"></a>
1059 <h4>SimplifyNodeVisitor.visit_Call</h4>
1060 <b>visit_Call</b>(<i>node</i>)
1061
1062 <p>
1063 Public method to process a Call node.
1064 </p>
1065 <dl>
1066
1067 <dt><i>node</i> (ast.Call)</dt>
1068 <dd>
1069 reference to the Call node
1070 </dd>
1071 </dl>
1072 <a NAME="SimplifyNodeVisitor.visit_ClassDef" ID="SimplifyNodeVisitor.visit_ClassDef"></a>
1073 <h4>SimplifyNodeVisitor.visit_ClassDef</h4>
1074 <b>visit_ClassDef</b>(<i>node</i>)
1075
1076 <p>
1077 Public method to process a ClassDef node.
1078 </p>
1079 <dl>
1080
1081 <dt><i>node</i> (ast.ClassDef)</dt>
1082 <dd>
1083 reference to the ClassDef node
1084 </dd>
1085 </dl>
1086 <a NAME="SimplifyNodeVisitor.visit_Compare" ID="SimplifyNodeVisitor.visit_Compare"></a>
1087 <h4>SimplifyNodeVisitor.visit_Compare</h4>
1088 <b>visit_Compare</b>(<i>node</i>)
1089
1090 <p>
1091 Public method to process a Compare node.
1092 </p>
1093 <dl>
1094
1095 <dt><i>node</i> (ast.Compare)</dt>
1096 <dd>
1097 reference to the Compare node
1098 </dd>
1099 </dl>
1100 <a NAME="SimplifyNodeVisitor.visit_Expr" ID="SimplifyNodeVisitor.visit_Expr"></a>
1101 <h4>SimplifyNodeVisitor.visit_Expr</h4>
1102 <b>visit_Expr</b>(<i>node</i>)
1103
1104 <p>
1105 Public method to process an Expr node.
1106 </p>
1107 <dl>
1108
1109 <dt><i>node</i> (ast.Expr)</dt>
1110 <dd>
1111 reference to the Expr node
1112 </dd>
1113 </dl>
1114 <a NAME="SimplifyNodeVisitor.visit_For" ID="SimplifyNodeVisitor.visit_For"></a>
1115 <h4>SimplifyNodeVisitor.visit_For</h4>
1116 <b>visit_For</b>(<i>node</i>)
1117
1118 <p>
1119 Public method to process a For node.
1120 </p>
1121 <dl>
1122
1123 <dt><i>node</i> (ast.For)</dt>
1124 <dd>
1125 reference to the For node
1126 </dd>
1127 </dl>
1128 <a NAME="SimplifyNodeVisitor.visit_If" ID="SimplifyNodeVisitor.visit_If"></a>
1129 <h4>SimplifyNodeVisitor.visit_If</h4>
1130 <b>visit_If</b>(<i>node</i>)
1131
1132 <p>
1133 Public method to process an If node.
1134 </p>
1135 <dl>
1136
1137 <dt><i>node</i> (ast.If)</dt>
1138 <dd>
1139 reference to the If node
1140 </dd>
1141 </dl>
1142 <a NAME="SimplifyNodeVisitor.visit_IfExp" ID="SimplifyNodeVisitor.visit_IfExp"></a>
1143 <h4>SimplifyNodeVisitor.visit_IfExp</h4>
1144 <b>visit_IfExp</b>(<i>node</i>)
1145
1146 <p>
1147 Public method to process an IfExp node.
1148 </p>
1149 <dl>
1150
1151 <dt><i>node</i> (ast.IfExp)</dt>
1152 <dd>
1153 reference to the IfExp node
1154 </dd>
1155 </dl>
1156 <a NAME="SimplifyNodeVisitor.visit_Try" ID="SimplifyNodeVisitor.visit_Try"></a>
1157 <h4>SimplifyNodeVisitor.visit_Try</h4>
1158 <b>visit_Try</b>(<i>node</i>)
1159
1160 <p>
1161 Public method to process a Try node.
1162 </p>
1163 <dl>
1164
1165 <dt><i>node</i> (ast.Try)</dt>
1166 <dd>
1167 reference to the Try node
1168 </dd>
1169 </dl>
1170 <a NAME="SimplifyNodeVisitor.visit_UnaryOp" ID="SimplifyNodeVisitor.visit_UnaryOp"></a>
1171 <h4>SimplifyNodeVisitor.visit_UnaryOp</h4>
1172 <b>visit_UnaryOp</b>(<i>node</i>)
1173
1174 <p>
1175 Public method to process a UnaryOp node.
1176 </p>
1177 <dl>
1178
1179 <dt><i>node</i> (ast.UnaryOp)</dt>
1180 <dd>
1181 reference to the UnaryOp node
1182 </dd>
1183 </dl>
1184 <a NAME="SimplifyNodeVisitor.visit_With" ID="SimplifyNodeVisitor.visit_With"></a>
1185 <h4>SimplifyNodeVisitor.visit_With</h4>
1186 <b>visit_With</b>(<i>node</i>)
1187
1188 <p>
1189 Public method to process a With node.
1190 </p>
1191 <dl>
1192
1193 <dt><i>node</i> (ast.With)</dt>
1194 <dd>
1195 reference to the With node
1196 </dd>
1197 </dl>
1198 <div align="right"><a href="#top">Up</a></div>
1199 <hr />
1200 </body></html>

eric ide

mercurial