|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Annotations.AnnotationsChecker</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.Annotations.AnnotationsChecker</h1> |
|
10 |
|
11 <p> |
|
12 Module implementing a checker for function type annotations. |
|
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="#AnnotationsChecker">AnnotationsChecker</a></td> |
|
25 <td>Class implementing a checker for function type annotations.</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="AnnotationsChecker" ID="AnnotationsChecker"></a> |
|
36 <h2>AnnotationsChecker</h2> |
|
37 |
|
38 <p> |
|
39 Class implementing a checker for function type annotations. |
|
40 </p> |
|
41 <h3>Derived from</h3> |
|
42 None |
|
43 <h3>Class Attributes</h3> |
|
44 |
|
45 <table> |
|
46 <tr><td>Codes</td></tr> |
|
47 </table> |
|
48 <h3>Class Methods</h3> |
|
49 |
|
50 <table> |
|
51 <tr><td>None</td></tr> |
|
52 </table> |
|
53 <h3>Methods</h3> |
|
54 |
|
55 <table> |
|
56 |
|
57 <tr> |
|
58 <td><a href="#AnnotationsChecker.__init__">AnnotationsChecker</a></td> |
|
59 <td>Constructor</td> |
|
60 </tr> |
|
61 <tr> |
|
62 <td><a href="#AnnotationsChecker.__argumentErrorClassifier">__argumentErrorClassifier</a></td> |
|
63 <td>Private method to classify an argument type annotation issue.</td> |
|
64 </tr> |
|
65 <tr> |
|
66 <td><a href="#AnnotationsChecker.__checkAnnotationComplexity">__checkAnnotationComplexity</a></td> |
|
67 <td>Private method to check the type annotation complexity.</td> |
|
68 </tr> |
|
69 <tr> |
|
70 <td><a href="#AnnotationsChecker.__checkAnnotationsCoverage">__checkAnnotationsCoverage</a></td> |
|
71 <td>Private method to check for function annotation coverage.</td> |
|
72 </tr> |
|
73 <tr> |
|
74 <td><a href="#AnnotationsChecker.__checkAnnotationsFuture">__checkAnnotationsFuture</a></td> |
|
75 <td>Private method to check the use of __future__ and typing imports.</td> |
|
76 </tr> |
|
77 <tr> |
|
78 <td><a href="#AnnotationsChecker.__checkFunctionAnnotations">__checkFunctionAnnotations</a></td> |
|
79 <td>Private method to check for function annotation issues.</td> |
|
80 </tr> |
|
81 <tr> |
|
82 <td><a href="#AnnotationsChecker.__classifyError">__classifyError</a></td> |
|
83 <td>Private method to classify the missing type annotation based on the Function & Argument metadata.</td> |
|
84 </tr> |
|
85 <tr> |
|
86 <td><a href="#AnnotationsChecker.__error">__error</a></td> |
|
87 <td>Private method to record an issue.</td> |
|
88 </tr> |
|
89 <tr> |
|
90 <td><a href="#AnnotationsChecker.__getAnnotationComplexity">__getAnnotationComplexity</a></td> |
|
91 <td>Private method to determine the annotation complexity.</td> |
|
92 </tr> |
|
93 <tr> |
|
94 <td><a href="#AnnotationsChecker.__getAnnotationLength">__getAnnotationLength</a></td> |
|
95 <td>Private method to determine the annotation length.</td> |
|
96 </tr> |
|
97 <tr> |
|
98 <td><a href="#AnnotationsChecker.__hasTypeAnnotations">__hasTypeAnnotations</a></td> |
|
99 <td>Private method to check for type annotations.</td> |
|
100 </tr> |
|
101 <tr> |
|
102 <td><a href="#AnnotationsChecker.__ignoreCode">__ignoreCode</a></td> |
|
103 <td>Private method to check if the message code should be ignored.</td> |
|
104 </tr> |
|
105 <tr> |
|
106 <td><a href="#AnnotationsChecker.__returnErrorClassifier">__returnErrorClassifier</a></td> |
|
107 <td>Private method to classify a return type annotation issue.</td> |
|
108 </tr> |
|
109 <tr> |
|
110 <td><a href="#AnnotationsChecker.run">run</a></td> |
|
111 <td>Public method to check the given source against annotation issues.</td> |
|
112 </tr> |
|
113 </table> |
|
114 <h3>Static Methods</h3> |
|
115 |
|
116 <table> |
|
117 <tr><td>None</td></tr> |
|
118 </table> |
|
119 |
|
120 <a NAME="AnnotationsChecker.__init__" ID="AnnotationsChecker.__init__"></a> |
|
121 <h4>AnnotationsChecker (Constructor)</h4> |
|
122 <b>AnnotationsChecker</b>(<i>source, filename, tree, select, ignore, expected, repeat, args</i>) |
|
123 |
|
124 <p> |
|
125 Constructor |
|
126 </p> |
|
127 <dl> |
|
128 |
|
129 <dt><i>source</i> (list of str)</dt> |
|
130 <dd> |
|
131 source code to be checked |
|
132 </dd> |
|
133 <dt><i>filename</i> (str)</dt> |
|
134 <dd> |
|
135 name of the source file |
|
136 </dd> |
|
137 <dt><i>tree</i> (ast.Module)</dt> |
|
138 <dd> |
|
139 AST tree of the source code |
|
140 </dd> |
|
141 <dt><i>select</i> (list of str)</dt> |
|
142 <dd> |
|
143 list of selected codes |
|
144 </dd> |
|
145 <dt><i>ignore</i> (list of str)</dt> |
|
146 <dd> |
|
147 list of codes to be ignored |
|
148 </dd> |
|
149 <dt><i>expected</i> (list of str)</dt> |
|
150 <dd> |
|
151 list of expected codes |
|
152 </dd> |
|
153 <dt><i>repeat</i> (bool)</dt> |
|
154 <dd> |
|
155 flag indicating to report each occurrence of a code |
|
156 </dd> |
|
157 <dt><i>args</i> (dict)</dt> |
|
158 <dd> |
|
159 dictionary of arguments for the annotation checks |
|
160 </dd> |
|
161 </dl> |
|
162 <a NAME="AnnotationsChecker.__argumentErrorClassifier" ID="AnnotationsChecker.__argumentErrorClassifier"></a> |
|
163 <h4>AnnotationsChecker.__argumentErrorClassifier</h4> |
|
164 <b>__argumentErrorClassifier</b>(<i>isClassMethod, isFirstArg, classDecoratorType, annotationType</i>) |
|
165 |
|
166 <p> |
|
167 Private method to classify an argument type annotation issue. |
|
168 </p> |
|
169 <dl> |
|
170 |
|
171 <dt><i>isClassMethod</i> (bool)</dt> |
|
172 <dd> |
|
173 flag indicating a classmethod type function |
|
174 </dd> |
|
175 <dt><i>isFirstArg</i> (bool)</dt> |
|
176 <dd> |
|
177 flag indicating the first argument |
|
178 </dd> |
|
179 <dt><i>classDecoratorType</i> (enums.ClassDecoratorType)</dt> |
|
180 <dd> |
|
181 type of class decorator |
|
182 </dd> |
|
183 <dt><i>annotationType</i> (AnnotationType)</dt> |
|
184 <dd> |
|
185 type of annotation |
|
186 </dd> |
|
187 </dl> |
|
188 <dl> |
|
189 <dt>Return:</dt> |
|
190 <dd> |
|
191 error code |
|
192 </dd> |
|
193 </dl> |
|
194 <dl> |
|
195 <dt>Return Type:</dt> |
|
196 <dd> |
|
197 str |
|
198 </dd> |
|
199 </dl> |
|
200 <a NAME="AnnotationsChecker.__checkAnnotationComplexity" ID="AnnotationsChecker.__checkAnnotationComplexity"></a> |
|
201 <h4>AnnotationsChecker.__checkAnnotationComplexity</h4> |
|
202 <b>__checkAnnotationComplexity</b>(<i></i>) |
|
203 |
|
204 <p> |
|
205 Private method to check the type annotation complexity. |
|
206 </p> |
|
207 <a NAME="AnnotationsChecker.__checkAnnotationsCoverage" ID="AnnotationsChecker.__checkAnnotationsCoverage"></a> |
|
208 <h4>AnnotationsChecker.__checkAnnotationsCoverage</h4> |
|
209 <b>__checkAnnotationsCoverage</b>(<i></i>) |
|
210 |
|
211 <p> |
|
212 Private method to check for function annotation coverage. |
|
213 </p> |
|
214 <a NAME="AnnotationsChecker.__checkAnnotationsFuture" ID="AnnotationsChecker.__checkAnnotationsFuture"></a> |
|
215 <h4>AnnotationsChecker.__checkAnnotationsFuture</h4> |
|
216 <b>__checkAnnotationsFuture</b>(<i></i>) |
|
217 |
|
218 <p> |
|
219 Private method to check the use of __future__ and typing imports. |
|
220 </p> |
|
221 <a NAME="AnnotationsChecker.__checkFunctionAnnotations" ID="AnnotationsChecker.__checkFunctionAnnotations"></a> |
|
222 <h4>AnnotationsChecker.__checkFunctionAnnotations</h4> |
|
223 <b>__checkFunctionAnnotations</b>(<i></i>) |
|
224 |
|
225 <p> |
|
226 Private method to check for function annotation issues. |
|
227 </p> |
|
228 <a NAME="AnnotationsChecker.__classifyError" ID="AnnotationsChecker.__classifyError"></a> |
|
229 <h4>AnnotationsChecker.__classifyError</h4> |
|
230 <b>__classifyError</b>(<i>function, arg</i>) |
|
231 |
|
232 <p> |
|
233 Private method to classify the missing type annotation based on the |
|
234 Function & Argument metadata. |
|
235 </p> |
|
236 <p> |
|
237 For the currently defined rules & program flow, the assumption can be |
|
238 made that an argument passed to this method will match a linting error, |
|
239 and will only match a single linting error |
|
240 </p> |
|
241 <p> |
|
242 This function provides an initial classificaton, then passes relevant |
|
243 attributes to cached helper function(s). |
|
244 </p> |
|
245 <dl> |
|
246 |
|
247 <dt><i>function</i> (Function)</dt> |
|
248 <dd> |
|
249 reference to the Function object |
|
250 </dd> |
|
251 <dt><i>arg</i> (Argument)</dt> |
|
252 <dd> |
|
253 reference to the Argument object |
|
254 </dd> |
|
255 </dl> |
|
256 <a NAME="AnnotationsChecker.__error" ID="AnnotationsChecker.__error"></a> |
|
257 <h4>AnnotationsChecker.__error</h4> |
|
258 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
|
259 |
|
260 <p> |
|
261 Private method to record an issue. |
|
262 </p> |
|
263 <dl> |
|
264 |
|
265 <dt><i>lineNumber</i> (int)</dt> |
|
266 <dd> |
|
267 line number of the issue |
|
268 </dd> |
|
269 <dt><i>offset</i> (int)</dt> |
|
270 <dd> |
|
271 position within line of the issue |
|
272 </dd> |
|
273 <dt><i>code</i> (str)</dt> |
|
274 <dd> |
|
275 message code |
|
276 </dd> |
|
277 <dt><i>args</i> (list)</dt> |
|
278 <dd> |
|
279 arguments for the message |
|
280 </dd> |
|
281 </dl> |
|
282 <a NAME="AnnotationsChecker.__getAnnotationComplexity" ID="AnnotationsChecker.__getAnnotationComplexity"></a> |
|
283 <h4>AnnotationsChecker.__getAnnotationComplexity</h4> |
|
284 <b>__getAnnotationComplexity</b>(<i>annotationNode, defaultComplexity=1</i>) |
|
285 |
|
286 <p> |
|
287 Private method to determine the annotation complexity. |
|
288 </p> |
|
289 <dl> |
|
290 |
|
291 <dt><i>annotationNode</i> (ast.AST)</dt> |
|
292 <dd> |
|
293 reference to the node to determine the annotation |
|
294 complexity for |
|
295 </dd> |
|
296 <dt><i>defaultComplexity</i> (int)</dt> |
|
297 <dd> |
|
298 default complexity value |
|
299 </dd> |
|
300 </dl> |
|
301 <dl> |
|
302 <dt>Return:</dt> |
|
303 <dd> |
|
304 annotation complexity |
|
305 </dd> |
|
306 </dl> |
|
307 <dl> |
|
308 <dt>Return Type:</dt> |
|
309 <dd> |
|
310 = int |
|
311 </dd> |
|
312 </dl> |
|
313 <a NAME="AnnotationsChecker.__getAnnotationLength" ID="AnnotationsChecker.__getAnnotationLength"></a> |
|
314 <h4>AnnotationsChecker.__getAnnotationLength</h4> |
|
315 <b>__getAnnotationLength</b>(<i>annotationNode</i>) |
|
316 |
|
317 <p> |
|
318 Private method to determine the annotation length. |
|
319 </p> |
|
320 <dl> |
|
321 |
|
322 <dt><i>annotationNode</i> (ast.AST)</dt> |
|
323 <dd> |
|
324 reference to the node to determine the annotation |
|
325 length for |
|
326 </dd> |
|
327 </dl> |
|
328 <dl> |
|
329 <dt>Return:</dt> |
|
330 <dd> |
|
331 annotation length |
|
332 </dd> |
|
333 </dl> |
|
334 <dl> |
|
335 <dt>Return Type:</dt> |
|
336 <dd> |
|
337 = int |
|
338 </dd> |
|
339 </dl> |
|
340 <a NAME="AnnotationsChecker.__hasTypeAnnotations" ID="AnnotationsChecker.__hasTypeAnnotations"></a> |
|
341 <h4>AnnotationsChecker.__hasTypeAnnotations</h4> |
|
342 <b>__hasTypeAnnotations</b>(<i>funcNode</i>) |
|
343 |
|
344 <p> |
|
345 Private method to check for type annotations. |
|
346 </p> |
|
347 <dl> |
|
348 |
|
349 <dt><i>funcNode</i> (ast.AsyncFunctionDef or ast.FunctionDef)</dt> |
|
350 <dd> |
|
351 reference to the function definition node to be checked |
|
352 </dd> |
|
353 </dl> |
|
354 <dl> |
|
355 <dt>Return:</dt> |
|
356 <dd> |
|
357 flag indicating the presence of type annotations |
|
358 </dd> |
|
359 </dl> |
|
360 <dl> |
|
361 <dt>Return Type:</dt> |
|
362 <dd> |
|
363 bool |
|
364 </dd> |
|
365 </dl> |
|
366 <a NAME="AnnotationsChecker.__ignoreCode" ID="AnnotationsChecker.__ignoreCode"></a> |
|
367 <h4>AnnotationsChecker.__ignoreCode</h4> |
|
368 <b>__ignoreCode</b>(<i>code</i>) |
|
369 |
|
370 <p> |
|
371 Private method to check if the message code should be ignored. |
|
372 </p> |
|
373 <dl> |
|
374 |
|
375 <dt><i>code</i> (str)</dt> |
|
376 <dd> |
|
377 message code to check for |
|
378 </dd> |
|
379 </dl> |
|
380 <dl> |
|
381 <dt>Return:</dt> |
|
382 <dd> |
|
383 flag indicating to ignore the given code |
|
384 </dd> |
|
385 </dl> |
|
386 <dl> |
|
387 <dt>Return Type:</dt> |
|
388 <dd> |
|
389 bool |
|
390 </dd> |
|
391 </dl> |
|
392 <a NAME="AnnotationsChecker.__returnErrorClassifier" ID="AnnotationsChecker.__returnErrorClassifier"></a> |
|
393 <h4>AnnotationsChecker.__returnErrorClassifier</h4> |
|
394 <b>__returnErrorClassifier</b>(<i>isClassMethod, classDecoratorType, functionType</i>) |
|
395 |
|
396 <p> |
|
397 Private method to classify a return type annotation issue. |
|
398 </p> |
|
399 <dl> |
|
400 |
|
401 <dt><i>isClassMethod</i> (bool)</dt> |
|
402 <dd> |
|
403 flag indicating a classmethod type function |
|
404 </dd> |
|
405 <dt><i>classDecoratorType</i> (ClassDecoratorType)</dt> |
|
406 <dd> |
|
407 type of class decorator |
|
408 </dd> |
|
409 <dt><i>functionType</i> (FunctionType)</dt> |
|
410 <dd> |
|
411 type of function |
|
412 </dd> |
|
413 </dl> |
|
414 <dl> |
|
415 <dt>Return:</dt> |
|
416 <dd> |
|
417 error code |
|
418 </dd> |
|
419 </dl> |
|
420 <dl> |
|
421 <dt>Return Type:</dt> |
|
422 <dd> |
|
423 str |
|
424 </dd> |
|
425 </dl> |
|
426 <a NAME="AnnotationsChecker.run" ID="AnnotationsChecker.run"></a> |
|
427 <h4>AnnotationsChecker.run</h4> |
|
428 <b>run</b>(<i></i>) |
|
429 |
|
430 <p> |
|
431 Public method to check the given source against annotation issues. |
|
432 </p> |
|
433 <div align="right"><a href="#top">Up</a></div> |
|
434 <hr /> |
|
435 </body></html> |