src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.NameOrder.NameOrderChecker.html

branch
eric7
changeset 10046
35b27af462ef
child 10054
d7a47f0cff2b
equal deleted inserted replaced
10045:f5c57f8d17a4 10046:35b27af462ef
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.NameOrder.NameOrderChecker</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.NameOrder.NameOrderChecker</h1>
10
11 <p>
12 Module implementing a checker for import statements.
13 </p>
14 <h3>Global Attributes</h3>
15
16 <table>
17 <tr><td>None</td></tr>
18 </table>
19 <h3>Classes</h3>
20
21 <table>
22
23 <tr>
24 <td><a href="#NameOrderChecker">NameOrderChecker</a></td>
25 <td>Class implementing a checker for name ordering.</td>
26 </tr>
27 </table>
28 <h3>Functions</h3>
29
30 <table>
31 <tr><td>None</td></tr>
32 </table>
33 <hr />
34 <hr />
35 <a NAME="NameOrderChecker" ID="NameOrderChecker"></a>
36 <h2>NameOrderChecker</h2>
37
38 <p>
39 Class implementing a checker for name ordering.
40 </p>
41 <p>
42 Note: Name ordering is checked for import statements, the '__all__' statement
43 and exception names of exception handlers.
44 </p>
45 <h3>Derived from</h3>
46 None
47 <h3>Class Attributes</h3>
48
49 <table>
50 <tr><td>Codes</td></tr>
51 </table>
52 <h3>Class Methods</h3>
53
54 <table>
55 <tr><td>None</td></tr>
56 </table>
57 <h3>Methods</h3>
58
59 <table>
60
61 <tr>
62 <td><a href="#NameOrderChecker.__init__">NameOrderChecker</a></td>
63 <td>Constructor</td>
64 </tr>
65 <tr>
66 <td><a href="#NameOrderChecker.__atoi">__atoi</a></td>
67 <td>Private method to convert the given text to an integer number.</td>
68 </tr>
69 <tr>
70 <td><a href="#NameOrderChecker.__checkNameOrder">__checkNameOrder</a></td>
71 <td>Private method to check the order of import statements.</td>
72 </tr>
73 <tr>
74 <td><a href="#NameOrderChecker.__error">__error</a></td>
75 <td>Private method to record an issue.</td>
76 </tr>
77 <tr>
78 <td><a href="#NameOrderChecker.__findErrorInAll">__findErrorInAll</a></td>
79 <td>Private method to check the '__all__' node for errors.</td>
80 </tr>
81 <tr>
82 <td><a href="#NameOrderChecker.__findExceptionListErrors">__findExceptionListErrors</a></td>
83 <td>Private method to check the exception node for errors.</td>
84 </tr>
85 <tr>
86 <td><a href="#NameOrderChecker.__findExceptionListNodes">__findExceptionListNodes</a></td>
87 <td>Private method to find all exception types handled by given tree.</td>
88 </tr>
89 <tr>
90 <td><a href="#NameOrderChecker.__findExceptionListStr">__findExceptionListStr</a></td>
91 <td>Private method to get the exception name out of an exception handler type node.</td>
92 </tr>
93 <tr>
94 <td><a href="#NameOrderChecker.__findNodes">__findNodes</a></td>
95 <td>Private method to find all import and import from nodes of the given tree.</td>
96 </tr>
97 <tr>
98 <td><a href="#NameOrderChecker.__ignoreCode">__ignoreCode</a></td>
99 <td>Private method to check if the message code should be ignored.</td>
100 </tr>
101 <tr>
102 <td><a href="#NameOrderChecker.__naturalKeys">__naturalKeys</a></td>
103 <td>Private method to generate keys for natural sorting.</td>
104 </tr>
105 <tr>
106 <td><a href="#NameOrderChecker.__naturally">__naturally</a></td>
107 <td>Private method to sort the given list of names naturally.</td>
108 </tr>
109 <tr>
110 <td><a href="#NameOrderChecker.keyCallback">keyCallback</a></td>
111 <td></td>
112 </tr>
113 <tr>
114 <td><a href="#NameOrderChecker.moduleKey">moduleKey</a></td>
115 <td>Public method to generate a key for the given module name.</td>
116 </tr>
117 <tr>
118 <td><a href="#NameOrderChecker.run">run</a></td>
119 <td>Public method to check the given source against miscellaneous conditions.</td>
120 </tr>
121 <tr>
122 <td><a href="#NameOrderChecker.sorted">sorted</a></td>
123 <td>Public method to sort the given list of names.</td>
124 </tr>
125 </table>
126 <h3>Static Methods</h3>
127
128 <table>
129 <tr><td>None</td></tr>
130 </table>
131
132 <a NAME="NameOrderChecker.__init__" ID="NameOrderChecker.__init__"></a>
133 <h4>NameOrderChecker (Constructor)</h4>
134 <b>NameOrderChecker</b>(<i>source, filename, tree, select, ignore, expected, repeat, args</i>)
135
136 <p>
137 Constructor
138 </p>
139 <dl>
140
141 <dt><i>source</i> (list of str)</dt>
142 <dd>
143 source code to be checked
144 </dd>
145 <dt><i>filename</i> (str)</dt>
146 <dd>
147 name of the source file
148 </dd>
149 <dt><i>tree</i> (ast.Module)</dt>
150 <dd>
151 AST tree of the source code
152 </dd>
153 <dt><i>select</i> (list of str)</dt>
154 <dd>
155 list of selected codes
156 </dd>
157 <dt><i>ignore</i> (list of str)</dt>
158 <dd>
159 list of codes to be ignored
160 </dd>
161 <dt><i>expected</i> (list of str)</dt>
162 <dd>
163 list of expected codes
164 </dd>
165 <dt><i>repeat</i> (bool)</dt>
166 <dd>
167 flag indicating to report each occurrence of a code
168 </dd>
169 <dt><i>args</i> (dict)</dt>
170 <dd>
171 dictionary of arguments for the various checks
172 </dd>
173 </dl>
174 <a NAME="NameOrderChecker.__atoi" ID="NameOrderChecker.__atoi"></a>
175 <h4>NameOrderChecker.__atoi</h4>
176 <b>__atoi</b>(<i>text</i>)
177
178 <p>
179 Private method to convert the given text to an integer number.
180 </p>
181 <dl>
182
183 <dt><i>text</i> (str)</dt>
184 <dd>
185 text to be converted
186 </dd>
187 </dl>
188 <dl>
189 <dt>Return:</dt>
190 <dd>
191 integer number
192 </dd>
193 </dl>
194 <dl>
195 <dt>Return Type:</dt>
196 <dd>
197 int
198 </dd>
199 </dl>
200 <a NAME="NameOrderChecker.__checkNameOrder" ID="NameOrderChecker.__checkNameOrder"></a>
201 <h4>NameOrderChecker.__checkNameOrder</h4>
202 <b>__checkNameOrder</b>(<i></i>)
203
204 <p>
205 Private method to check the order of import statements.
206 </p>
207 <a NAME="NameOrderChecker.__error" ID="NameOrderChecker.__error"></a>
208 <h4>NameOrderChecker.__error</h4>
209 <b>__error</b>(<i>lineNumber, offset, code, *args</i>)
210
211 <p>
212 Private method to record an issue.
213 </p>
214 <dl>
215
216 <dt><i>lineNumber</i> (int)</dt>
217 <dd>
218 line number of the issue
219 </dd>
220 <dt><i>offset</i> (int)</dt>
221 <dd>
222 position within line of the issue
223 </dd>
224 <dt><i>code</i> (str)</dt>
225 <dd>
226 message code
227 </dd>
228 <dt><i>args</i> (list)</dt>
229 <dd>
230 arguments for the message
231 </dd>
232 </dl>
233 <a NAME="NameOrderChecker.__findErrorInAll" ID="NameOrderChecker.__findErrorInAll"></a>
234 <h4>NameOrderChecker.__findErrorInAll</h4>
235 <b>__findErrorInAll</b>(<i>node</i>)
236
237 <p>
238 Private method to check the '__all__' node for errors.
239 </p>
240 <dl>
241
242 <dt><i>node</i> (ast.List or ast.Tuple)</dt>
243 <dd>
244 reference to the '__all__' node
245 </dd>
246 </dl>
247 <dl>
248 <dt>Return:</dt>
249 <dd>
250 tuple containing a reference to the node an error code and the error
251 arguments
252 </dd>
253 </dl>
254 <dl>
255 <dt>Return Type:</dt>
256 <dd>
257 tuple of (ast.List | ast.Tuple, str, str)
258 </dd>
259 </dl>
260 <a NAME="NameOrderChecker.__findExceptionListErrors" ID="NameOrderChecker.__findExceptionListErrors"></a>
261 <h4>NameOrderChecker.__findExceptionListErrors</h4>
262 <b>__findExceptionListErrors</b>(<i>nodes</i>)
263
264 <p>
265 Private method to check the exception node for errors.
266 </p>
267 <dl>
268
269 <dt><i>nodes</i> (list of ast.List or ast.Tuple)</dt>
270 <dd>
271 list of exception nodes
272 </dd>
273 </dl>
274 <dl>
275 <dt>Return:</dt>
276 <dd>
277 DESCRIPTION
278 </dd>
279 </dl>
280 <dl>
281 <dt>Return Type:</dt>
282 <dd>
283 TYPE
284 </dd>
285 </dl>
286 <a NAME="NameOrderChecker.__findExceptionListNodes" ID="NameOrderChecker.__findExceptionListNodes"></a>
287 <h4>NameOrderChecker.__findExceptionListNodes</h4>
288 <b>__findExceptionListNodes</b>(<i>tree</i>)
289
290 <p>
291 Private method to find all exception types handled by given tree.
292 </p>
293 <dl>
294
295 <dt><i>tree</i> (ast.AST)</dt>
296 <dd>
297 reference to the ast node tree to be parsed
298 </dd>
299 </dl>
300 <dl>
301 <dt>Return:</dt>
302 <dd>
303 list of exception types
304 </dd>
305 </dl>
306 <dl>
307 <dt>Return Type:</dt>
308 <dd>
309 list of ast.Name
310 </dd>
311 </dl>
312 <a NAME="NameOrderChecker.__findExceptionListStr" ID="NameOrderChecker.__findExceptionListStr"></a>
313 <h4>NameOrderChecker.__findExceptionListStr</h4>
314 <b>__findExceptionListStr</b>(<i>node</i>)
315
316 <p>
317 Private method to get the exception name out of an exception handler type node.
318 </p>
319 <dl>
320
321 <dt><i>node</i> (ast.Name or ast.Attribute)</dt>
322 <dd>
323 node to be treated
324 </dd>
325 </dl>
326 <dl>
327 <dt>Return:</dt>
328 <dd>
329 string containing the exception name
330 </dd>
331 </dl>
332 <dl>
333 <dt>Return Type:</dt>
334 <dd>
335 str
336 </dd>
337 </dl>
338 <a NAME="NameOrderChecker.__findNodes" ID="NameOrderChecker.__findNodes"></a>
339 <h4>NameOrderChecker.__findNodes</h4>
340 <b>__findNodes</b>(<i>tree</i>)
341
342 <p>
343 Private method to find all import and import from nodes of the given
344 tree.
345 </p>
346 <dl>
347
348 <dt><i>tree</i> (ast.AST)</dt>
349 <dd>
350 reference to the ast node tree to be parsed
351 </dd>
352 </dl>
353 <dl>
354 <dt>Return:</dt>
355 <dd>
356 tuple containing a list of import nodes, the '__all__' node and
357 exception nodes
358 </dd>
359 </dl>
360 <dl>
361 <dt>Return Type:</dt>
362 <dd>
363 tuple of (ast.Import | ast.ImportFrom, ast.List | ast.Tuple,
364 ast.List | ast.Tuple)
365 </dd>
366 </dl>
367 <a NAME="NameOrderChecker.__ignoreCode" ID="NameOrderChecker.__ignoreCode"></a>
368 <h4>NameOrderChecker.__ignoreCode</h4>
369 <b>__ignoreCode</b>(<i>code</i>)
370
371 <p>
372 Private method to check if the message code should be ignored.
373 </p>
374 <dl>
375
376 <dt><i>code</i> (str)</dt>
377 <dd>
378 message code to check for
379 </dd>
380 </dl>
381 <dl>
382 <dt>Return:</dt>
383 <dd>
384 flag indicating to ignore the given code
385 </dd>
386 </dl>
387 <dl>
388 <dt>Return Type:</dt>
389 <dd>
390 bool
391 </dd>
392 </dl>
393 <a NAME="NameOrderChecker.__naturalKeys" ID="NameOrderChecker.__naturalKeys"></a>
394 <h4>NameOrderChecker.__naturalKeys</h4>
395 <b>__naturalKeys</b>(<i>text</i>)
396
397 <p>
398 Private method to generate keys for natural sorting.
399 </p>
400 <dl>
401
402 <dt><i>text</i> (str)</dt>
403 <dd>
404 text to generate a key for
405 </dd>
406 </dl>
407 <dl>
408 <dt>Return:</dt>
409 <dd>
410 key for natural sorting
411 </dd>
412 </dl>
413 <dl>
414 <dt>Return Type:</dt>
415 <dd>
416 list of str or int
417 </dd>
418 </dl>
419 <a NAME="NameOrderChecker.__naturally" ID="NameOrderChecker.__naturally"></a>
420 <h4>NameOrderChecker.__naturally</h4>
421 <b>__naturally</b>(<i>toSort, key=None, reverse=False</i>)
422
423 <p>
424 Private method to sort the given list of names naturally.
425 </p>
426 <p>
427 Note: Natural sorting maintains the sort order of numbers (i.e.
428 [Q1, Q10, Q2] is sorted as [Q1, Q2, Q10] while the Python
429 standard sort would yield [Q1, Q10, Q2].
430 </p>
431 <dl>
432
433 <dt><i>toSort</i> (list of str)</dt>
434 <dd>
435 list of names to be sorted
436 </dd>
437 <dt><i>key</i> (function (optional))</dt>
438 <dd>
439 function to generate keys (defaults to None)
440 </dd>
441 <dt><i>reverse</i> (bool (optional))</dt>
442 <dd>
443 flag indicating a reverse sort (defaults to False)
444 </dd>
445 </dl>
446 <dl>
447 <dt>Return:</dt>
448 <dd>
449 sorted list of names
450 </dd>
451 </dl>
452 <dl>
453 <dt>Return Type:</dt>
454 <dd>
455 list of str
456 </dd>
457 </dl>
458 <a NAME="NameOrderChecker.keyCallback" ID="NameOrderChecker.keyCallback"></a>
459 <h4>NameOrderChecker.keyCallback</h4>
460 <b>keyCallback</b>(<i></i>)
461
462 <a NAME="NameOrderChecker.moduleKey" ID="NameOrderChecker.moduleKey"></a>
463 <h4>NameOrderChecker.moduleKey</h4>
464 <b>moduleKey</b>(<i>moduleName, subImports=False</i>)
465
466 <p>
467 Public method to generate a key for the given module name.
468 </p>
469 <dl>
470
471 <dt><i>moduleName</i> (str)</dt>
472 <dd>
473 module name
474 </dd>
475 <dt><i>subImports</i> (bool (optional))</dt>
476 <dd>
477 flag indicating a sub import like in
478 'from foo import bar, baz' (defaults to False)
479 </dd>
480 </dl>
481 <dl>
482 <dt>Return:</dt>
483 <dd>
484 generated key
485 </dd>
486 </dl>
487 <dl>
488 <dt>Return Type:</dt>
489 <dd>
490 str
491 </dd>
492 </dl>
493 <a NAME="NameOrderChecker.run" ID="NameOrderChecker.run"></a>
494 <h4>NameOrderChecker.run</h4>
495 <b>run</b>(<i></i>)
496
497 <p>
498 Public method to check the given source against miscellaneous
499 conditions.
500 </p>
501 <a NAME="NameOrderChecker.sorted" ID="NameOrderChecker.sorted"></a>
502 <h4>NameOrderChecker.sorted</h4>
503 <b>sorted</b>(<i>toSort, key=None, reverse=False</i>)
504
505 <p>
506 Public method to sort the given list of names.
507 </p>
508 <dl>
509
510 <dt><i>toSort</i> (list of str)</dt>
511 <dd>
512 list of names to be sorted
513 </dd>
514 <dt><i>key</i> (function (optional))</dt>
515 <dd>
516 function to generate keys (defaults to None)
517 </dd>
518 <dt><i>reverse</i> (bool (optional))</dt>
519 <dd>
520 flag indicating a reverse sort (defaults to False)
521 </dd>
522 </dl>
523 <dl>
524 <dt>Return:</dt>
525 <dd>
526 sorted list of names
527 </dd>
528 </dl>
529 <dl>
530 <dt>Return Type:</dt>
531 <dd>
532 list of str
533 </dd>
534 </dl>
535 <div align="right"><a href="#top">Up</a></div>
536 <hr />
537 </body></html>

eric ide

mercurial