eric6/Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.Annotations.AnnotationsChecker.html

changeset 7784
3257703e10c5
child 7989
a21d673a8f99
equal deleted inserted replaced
7783:36f66ce496bd 7784:3257703e10c5
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric6.Plugins.CheckerPlugins.CodeStyleChecker.Annotations.AnnotationsChecker</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.Annotations.AnnotationsChecker</h1>
24
25 <p>
26 Module implementing a checker for function type annotations.
27 </p>
28 <h3>Global Attributes</h3>
29
30 <table>
31 <tr><td>None</td></tr>
32 </table>
33 <h3>Classes</h3>
34
35 <table>
36
37 <tr>
38 <td><a href="#AnnotationsChecker">AnnotationsChecker</a></td>
39 <td>Class implementing a checker for function type annotations.</td>
40 </tr>
41 <tr>
42 <td><a href="#FunctionVisitor">FunctionVisitor</a></td>
43 <td>Class implementing a node visitor to check function annotations.</td>
44 </tr>
45 </table>
46 <h3>Functions</h3>
47
48 <table>
49
50 <tr>
51 <td><a href="#getAnnotationComplexity">getAnnotationComplexity</a></td>
52 <td>Function to determine the annotation complexity.</td>
53 </tr>
54 <tr>
55 <td><a href="#hasTypeAnnotations">hasTypeAnnotations</a></td>
56 <td>Function to check for type annotations.</td>
57 </tr>
58 </table>
59 <hr />
60 <hr />
61 <a NAME="AnnotationsChecker" ID="AnnotationsChecker"></a>
62 <h2>AnnotationsChecker</h2>
63
64 <p>
65 Class implementing a checker for function type annotations.
66 </p>
67 <h3>Derived from</h3>
68 object
69 <h3>Class Attributes</h3>
70
71 <table>
72 <tr><td>Codes</td></tr>
73 </table>
74 <h3>Class Methods</h3>
75
76 <table>
77 <tr><td>None</td></tr>
78 </table>
79 <h3>Methods</h3>
80
81 <table>
82
83 <tr>
84 <td><a href="#AnnotationsChecker.__init__">AnnotationsChecker</a></td>
85 <td>Constructor</td>
86 </tr>
87 <tr>
88 <td><a href="#AnnotationsChecker.__checkAnnotationComplexity">__checkAnnotationComplexity</a></td>
89 <td>Private method to check the type annotation complexity.</td>
90 </tr>
91 <tr>
92 <td><a href="#AnnotationsChecker.__checkAnnotationsCoverage">__checkAnnotationsCoverage</a></td>
93 <td>Private method to check for function annotation coverage.</td>
94 </tr>
95 <tr>
96 <td><a href="#AnnotationsChecker.__checkFunctionAnnotations">__checkFunctionAnnotations</a></td>
97 <td>Private method to check for function annotation issues.</td>
98 </tr>
99 <tr>
100 <td><a href="#AnnotationsChecker.__error">__error</a></td>
101 <td>Private method to record an issue.</td>
102 </tr>
103 <tr>
104 <td><a href="#AnnotationsChecker.__generateTree">__generateTree</a></td>
105 <td>Private method to generate an AST for our source.</td>
106 </tr>
107 <tr>
108 <td><a href="#AnnotationsChecker.__ignoreCode">__ignoreCode</a></td>
109 <td>Private method to check if the message code should be ignored.</td>
110 </tr>
111 <tr>
112 <td><a href="#AnnotationsChecker.__reportInvalidSyntax">__reportInvalidSyntax</a></td>
113 <td>Private method to report a syntax error.</td>
114 </tr>
115 <tr>
116 <td><a href="#AnnotationsChecker.run">run</a></td>
117 <td>Public method to check the given source against annotation issues.</td>
118 </tr>
119 </table>
120 <h3>Static Methods</h3>
121
122 <table>
123 <tr><td>None</td></tr>
124 </table>
125
126 <a NAME="AnnotationsChecker.__init__" ID="AnnotationsChecker.__init__"></a>
127 <h4>AnnotationsChecker (Constructor)</h4>
128 <b>AnnotationsChecker</b>(<i>source, filename, select, ignore, expected, repeat, args</i>)
129
130 <p>
131 Constructor
132 </p>
133 <dl>
134
135 <dt><i>source</i> (list of str)</dt>
136 <dd>
137 source code to be checked
138 </dd>
139 <dt><i>filename</i> (str)</dt>
140 <dd>
141 name of the source file
142 </dd>
143 <dt><i>select</i> (list of str)</dt>
144 <dd>
145 list of selected codes
146 </dd>
147 <dt><i>ignore</i> (list of str)</dt>
148 <dd>
149 list of codes to be ignored
150 </dd>
151 <dt><i>expected</i> (list of str)</dt>
152 <dd>
153 list of expected codes
154 </dd>
155 <dt><i>repeat</i> (bool)</dt>
156 <dd>
157 flag indicating to report each occurrence of a code
158 </dd>
159 <dt><i>args</i> (dict)</dt>
160 <dd>
161 dictionary of arguments for the annotation checks
162 </dd>
163 </dl>
164 <a NAME="AnnotationsChecker.__checkAnnotationComplexity" ID="AnnotationsChecker.__checkAnnotationComplexity"></a>
165 <h4>AnnotationsChecker.__checkAnnotationComplexity</h4>
166 <b>__checkAnnotationComplexity</b>(<i></i>)
167
168 <p>
169 Private method to check the type annotation complexity.
170 </p>
171 <a NAME="AnnotationsChecker.__checkAnnotationsCoverage" ID="AnnotationsChecker.__checkAnnotationsCoverage"></a>
172 <h4>AnnotationsChecker.__checkAnnotationsCoverage</h4>
173 <b>__checkAnnotationsCoverage</b>(<i></i>)
174
175 <p>
176 Private method to check for function annotation coverage.
177 </p>
178 <a NAME="AnnotationsChecker.__checkFunctionAnnotations" ID="AnnotationsChecker.__checkFunctionAnnotations"></a>
179 <h4>AnnotationsChecker.__checkFunctionAnnotations</h4>
180 <b>__checkFunctionAnnotations</b>(<i></i>)
181
182 <p>
183 Private method to check for function annotation issues.
184 </p>
185 <a NAME="AnnotationsChecker.__error" ID="AnnotationsChecker.__error"></a>
186 <h4>AnnotationsChecker.__error</h4>
187 <b>__error</b>(<i>lineNumber, offset, code, *args</i>)
188
189 <p>
190 Private method to record an issue.
191 </p>
192 <dl>
193
194 <dt><i>lineNumber</i> (int)</dt>
195 <dd>
196 line number of the issue
197 </dd>
198 <dt><i>offset</i> (int)</dt>
199 <dd>
200 position within line of the issue
201 </dd>
202 <dt><i>code</i> (str)</dt>
203 <dd>
204 message code
205 </dd>
206 <dt><i>args</i> (list)</dt>
207 <dd>
208 arguments for the message
209 </dd>
210 </dl>
211 <a NAME="AnnotationsChecker.__generateTree" ID="AnnotationsChecker.__generateTree"></a>
212 <h4>AnnotationsChecker.__generateTree</h4>
213 <b>__generateTree</b>(<i></i>)
214
215 <p>
216 Private method to generate an AST for our source.
217 </p>
218 <dl>
219 <dt>Returns:</dt>
220 <dd>
221 generated AST
222 </dd>
223 </dl>
224 <dl>
225 <dt>Return Type:</dt>
226 <dd>
227 ast.Module
228 </dd>
229 </dl>
230 <a NAME="AnnotationsChecker.__ignoreCode" ID="AnnotationsChecker.__ignoreCode"></a>
231 <h4>AnnotationsChecker.__ignoreCode</h4>
232 <b>__ignoreCode</b>(<i>code</i>)
233
234 <p>
235 Private method to check if the message code should be ignored.
236 </p>
237 <dl>
238
239 <dt><i>code</i> (str)</dt>
240 <dd>
241 message code to check for
242 </dd>
243 </dl>
244 <dl>
245 <dt>Returns:</dt>
246 <dd>
247 flag indicating to ignore the given code
248 </dd>
249 </dl>
250 <dl>
251 <dt>Return Type:</dt>
252 <dd>
253 bool
254 </dd>
255 </dl>
256 <a NAME="AnnotationsChecker.__reportInvalidSyntax" ID="AnnotationsChecker.__reportInvalidSyntax"></a>
257 <h4>AnnotationsChecker.__reportInvalidSyntax</h4>
258 <b>__reportInvalidSyntax</b>(<i></i>)
259
260 <p>
261 Private method to report a syntax error.
262 </p>
263 <a NAME="AnnotationsChecker.run" ID="AnnotationsChecker.run"></a>
264 <h4>AnnotationsChecker.run</h4>
265 <b>run</b>(<i></i>)
266
267 <p>
268 Public method to check the given source against annotation issues.
269 </p>
270 <div align="right"><a href="#top">Up</a></div>
271 <hr />
272 <hr />
273 <a NAME="FunctionVisitor" ID="FunctionVisitor"></a>
274 <h2>FunctionVisitor</h2>
275
276 <p>
277 Class implementing a node visitor to check function annotations.
278 </p>
279 <p>
280 Note: this class is modelled after flake8-annotations checker.
281 </p>
282 <h3>Derived from</h3>
283 ast.NodeVisitor
284 <h3>Class Attributes</h3>
285
286 <table>
287 <tr><td>None</td></tr>
288 </table>
289 <h3>Class Methods</h3>
290
291 <table>
292 <tr><td>None</td></tr>
293 </table>
294 <h3>Methods</h3>
295
296 <table>
297
298 <tr>
299 <td><a href="#FunctionVisitor.__init__">FunctionVisitor</a></td>
300 <td>Constructor</td>
301 </tr>
302 <tr>
303 <td><a href="#FunctionVisitor.__checkFunctionNode">__checkFunctionNode</a></td>
304 <td>Private method to check an individual function definition node.</td>
305 </tr>
306 <tr>
307 <td><a href="#FunctionVisitor.__classifyArgumentError">__classifyArgumentError</a></td>
308 <td>Private method to classify and record an argument annotation issue.</td>
309 </tr>
310 <tr>
311 <td><a href="#FunctionVisitor.__classifyReturnError">__classifyReturnError</a></td>
312 <td>Private method to classify and record a return annotation issue.</td>
313 </tr>
314 <tr>
315 <td><a href="#FunctionVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td>
316 <td>Public method to handle an async function or method definition.</td>
317 </tr>
318 <tr>
319 <td><a href="#FunctionVisitor.visit_ClassDef">visit_ClassDef</a></td>
320 <td>Public method to handle class definitions.</td>
321 </tr>
322 <tr>
323 <td><a href="#FunctionVisitor.visit_FunctionDef">visit_FunctionDef</a></td>
324 <td>Public method to handle a function or method definition.</td>
325 </tr>
326 </table>
327 <h3>Static Methods</h3>
328
329 <table>
330 <tr><td>None</td></tr>
331 </table>
332
333 <a NAME="FunctionVisitor.__init__" ID="FunctionVisitor.__init__"></a>
334 <h4>FunctionVisitor (Constructor)</h4>
335 <b>FunctionVisitor</b>(<i>sourceLines</i>)
336
337 <p>
338 Constructor
339 </p>
340 <dl>
341
342 <dt><i>sourceLines</i> (list of str)</dt>
343 <dd>
344 lines of source code
345 </dd>
346 </dl>
347 <a NAME="FunctionVisitor.__checkFunctionNode" ID="FunctionVisitor.__checkFunctionNode"></a>
348 <h4>FunctionVisitor.__checkFunctionNode</h4>
349 <b>__checkFunctionNode</b>(<i>node, classMethod=False</i>)
350
351 <p>
352 Private method to check an individual function definition node.
353 </p>
354 <dl>
355
356 <dt><i>node</i> (ast.FunctionDef or ast.AsyncFunctionDef)</dt>
357 <dd>
358 reference to the node to be processed
359 </dd>
360 <dt><i>classMethod</i> (bool)</dt>
361 <dd>
362 flag indicating a class method
363 </dd>
364 </dl>
365 <a NAME="FunctionVisitor.__classifyArgumentError" ID="FunctionVisitor.__classifyArgumentError"></a>
366 <h4>FunctionVisitor.__classifyArgumentError</h4>
367 <b>__classifyArgumentError</b>(<i>argNode, argType, methodType</i>)
368
369 <p>
370 Private method to classify and record an argument annotation issue.
371 </p>
372 <dl>
373
374 <dt><i>argNode</i> (ast.arguments)</dt>
375 <dd>
376 reference to the argument node
377 </dd>
378 <dt><i>argType</i> (str)</dt>
379 <dd>
380 type of the argument node
381 </dd>
382 <dt><i>methodType</i> (str)</dt>
383 <dd>
384 type of method/function the argument belongs to
385 </dd>
386 </dl>
387 <a NAME="FunctionVisitor.__classifyReturnError" ID="FunctionVisitor.__classifyReturnError"></a>
388 <h4>FunctionVisitor.__classifyReturnError</h4>
389 <b>__classifyReturnError</b>(<i>methodType, visibilityType, lineno, colOffset</i>)
390
391 <p>
392 Private method to classify and record a return annotation issue.
393 </p>
394 <dl>
395
396 <dt><i>methodType</i> (str)</dt>
397 <dd>
398 type of method/function the argument belongs to
399 </dd>
400 <dt><i>visibilityType</i> (str)</dt>
401 <dd>
402 visibility of the function
403 </dd>
404 <dt><i>lineno</i> (int)</dt>
405 <dd>
406 line number
407 </dd>
408 <dt><i>colOffset</i> (int)</dt>
409 <dd>
410 column number
411 </dd>
412 </dl>
413 <a NAME="FunctionVisitor.visit_AsyncFunctionDef" ID="FunctionVisitor.visit_AsyncFunctionDef"></a>
414 <h4>FunctionVisitor.visit_AsyncFunctionDef</h4>
415 <b>visit_AsyncFunctionDef</b>(<i>node</i>)
416
417 <p>
418 Public method to handle an async function or method definition.
419 </p>
420 <dl>
421
422 <dt><i>node</i> (ast.AsyncFunctionDef)</dt>
423 <dd>
424 reference to the node to be processed
425 </dd>
426 </dl>
427 <a NAME="FunctionVisitor.visit_ClassDef" ID="FunctionVisitor.visit_ClassDef"></a>
428 <h4>FunctionVisitor.visit_ClassDef</h4>
429 <b>visit_ClassDef</b>(<i>node</i>)
430
431 <p>
432 Public method to handle class definitions.
433 </p>
434 <dl>
435
436 <dt><i>node</i> (ast.ClassDef)</dt>
437 <dd>
438 reference to the node to be processed
439 </dd>
440 </dl>
441 <a NAME="FunctionVisitor.visit_FunctionDef" ID="FunctionVisitor.visit_FunctionDef"></a>
442 <h4>FunctionVisitor.visit_FunctionDef</h4>
443 <b>visit_FunctionDef</b>(<i>node</i>)
444
445 <p>
446 Public method to handle a function or method definition.
447 </p>
448 <dl>
449
450 <dt><i>node</i> (ast.FunctionDef)</dt>
451 <dd>
452 reference to the node to be processed
453 </dd>
454 </dl>
455 <div align="right"><a href="#top">Up</a></div>
456 <hr />
457 <hr />
458 <a NAME="getAnnotationComplexity" ID="getAnnotationComplexity"></a>
459 <h2>getAnnotationComplexity</h2>
460 <b>getAnnotationComplexity</b>(<i>annotationNode</i>)
461
462 <p>
463 Function to determine the annotation complexity.
464 </p>
465 <dl>
466
467 <dt><i>annotationNode</i> (ast.AST)</dt>
468 <dd>
469 reference to the node to determine the annotation
470 complexity for
471 </dd>
472 </dl>
473 <dl>
474 <dt>Returns:</dt>
475 <dd>
476 annotation complexity
477 </dd>
478 </dl>
479 <dl>
480 <dt>Return Type:</dt>
481 <dd>
482 = int
483 </dd>
484 </dl>
485 <div align="right"><a href="#top">Up</a></div>
486 <hr />
487 <hr />
488 <a NAME="hasTypeAnnotations" ID="hasTypeAnnotations"></a>
489 <h2>hasTypeAnnotations</h2>
490 <b>hasTypeAnnotations</b>(<i>funcNode</i>)
491
492 <p>
493 Function to check for type annotations.
494 </p>
495 <dl>
496
497 <dt><i>funcNode</i> (ast.AsyncFunctionDef or ast.FunctionDef)</dt>
498 <dd>
499 reference to the function definition node to be checked
500 </dd>
501 </dl>
502 <dl>
503 <dt>Returns:</dt>
504 <dd>
505 flag indicating the presence of type annotations
506 </dd>
507 </dl>
508 <dl>
509 <dt>Return Type:</dt>
510 <dd>
511 bool
512 </dd>
513 </dl>
514 <div align="right"><a href="#top">Up</a></div>
515 <hr />
516 </body></html>

eric ide

mercurial