95 <tr> |
87 <tr> |
96 <td><a href="#AnnotationsChecker.__checkFunctionAnnotations">__checkFunctionAnnotations</a></td> |
88 <td><a href="#AnnotationsChecker.__checkFunctionAnnotations">__checkFunctionAnnotations</a></td> |
97 <td>Private method to check for function annotation issues.</td> |
89 <td>Private method to check for function annotation issues.</td> |
98 </tr> |
90 </tr> |
99 <tr> |
91 <tr> |
|
92 <td><a href="#AnnotationsChecker.__classifyError">__classifyError</a></td> |
|
93 <td>Private method to classify the missing type annotation based on the Function & Argument metadata.</td> |
|
94 </tr> |
|
95 <tr> |
100 <td><a href="#AnnotationsChecker.__error">__error</a></td> |
96 <td><a href="#AnnotationsChecker.__error">__error</a></td> |
101 <td>Private method to record an issue.</td> |
97 <td>Private method to record an issue.</td> |
102 </tr> |
98 </tr> |
103 <tr> |
99 <tr> |
|
100 <td><a href="#AnnotationsChecker.__getAnnotationComplexity">__getAnnotationComplexity</a></td> |
|
101 <td>Private method to determine the annotation complexity.</td> |
|
102 </tr> |
|
103 <tr> |
|
104 <td><a href="#AnnotationsChecker.__getAnnotationLength">__getAnnotationLength</a></td> |
|
105 <td>Private method to determine the annotation length.</td> |
|
106 </tr> |
|
107 <tr> |
|
108 <td><a href="#AnnotationsChecker.__hasTypeAnnotations">__hasTypeAnnotations</a></td> |
|
109 <td>Private method to check for type annotations.</td> |
|
110 </tr> |
|
111 <tr> |
104 <td><a href="#AnnotationsChecker.__ignoreCode">__ignoreCode</a></td> |
112 <td><a href="#AnnotationsChecker.__ignoreCode">__ignoreCode</a></td> |
105 <td>Private method to check if the message code should be ignored.</td> |
113 <td>Private method to check if the message code should be ignored.</td> |
|
114 </tr> |
|
115 <tr> |
|
116 <td><a href="#AnnotationsChecker.__returnErrorClassifier">__returnErrorClassifier</a></td> |
|
117 <td>Private method to classify a return type annotation issue.</td> |
106 </tr> |
118 </tr> |
107 <tr> |
119 <tr> |
108 <td><a href="#AnnotationsChecker.run">run</a></td> |
120 <td><a href="#AnnotationsChecker.run">run</a></td> |
109 <td>Public method to check the given source against annotation issues.</td> |
121 <td>Public method to check the given source against annotation issues.</td> |
110 </tr> |
122 </tr> |
155 <dt><i>args</i> (dict)</dt> |
167 <dt><i>args</i> (dict)</dt> |
156 <dd> |
168 <dd> |
157 dictionary of arguments for the annotation checks |
169 dictionary of arguments for the annotation checks |
158 </dd> |
170 </dd> |
159 </dl> |
171 </dl> |
|
172 <a NAME="AnnotationsChecker.__argumentErrorClassifier" ID="AnnotationsChecker.__argumentErrorClassifier"></a> |
|
173 <h4>AnnotationsChecker.__argumentErrorClassifier</h4> |
|
174 <b>__argumentErrorClassifier</b>(<i>isClassMethod, isFirstArg, classDecoratorType, annotationType</i>) |
|
175 |
|
176 <p> |
|
177 Private method to classify an argument type annotation issue. |
|
178 </p> |
|
179 <dl> |
|
180 |
|
181 <dt><i>isClassMethod</i> (bool)</dt> |
|
182 <dd> |
|
183 flag indicating a classmethod type function |
|
184 </dd> |
|
185 <dt><i>isFirstArg</i> (bool)</dt> |
|
186 <dd> |
|
187 flag indicating the first argument |
|
188 </dd> |
|
189 <dt><i>classDecoratorType</i> (enums.ClassDecoratorType)</dt> |
|
190 <dd> |
|
191 type of class decorator |
|
192 </dd> |
|
193 <dt><i>annotationType</i> (AnnotationType)</dt> |
|
194 <dd> |
|
195 type of annotation |
|
196 </dd> |
|
197 </dl> |
|
198 <dl> |
|
199 <dt>Return:</dt> |
|
200 <dd> |
|
201 error code |
|
202 </dd> |
|
203 </dl> |
|
204 <dl> |
|
205 <dt>Return Type:</dt> |
|
206 <dd> |
|
207 str |
|
208 </dd> |
|
209 </dl> |
160 <a NAME="AnnotationsChecker.__checkAnnotationComplexity" ID="AnnotationsChecker.__checkAnnotationComplexity"></a> |
210 <a NAME="AnnotationsChecker.__checkAnnotationComplexity" ID="AnnotationsChecker.__checkAnnotationComplexity"></a> |
161 <h4>AnnotationsChecker.__checkAnnotationComplexity</h4> |
211 <h4>AnnotationsChecker.__checkAnnotationComplexity</h4> |
162 <b>__checkAnnotationComplexity</b>(<i></i>) |
212 <b>__checkAnnotationComplexity</b>(<i></i>) |
163 |
213 |
164 <p> |
214 <p> |
176 <b>__checkFunctionAnnotations</b>(<i></i>) |
226 <b>__checkFunctionAnnotations</b>(<i></i>) |
177 |
227 |
178 <p> |
228 <p> |
179 Private method to check for function annotation issues. |
229 Private method to check for function annotation issues. |
180 </p> |
230 </p> |
|
231 <a NAME="AnnotationsChecker.__classifyError" ID="AnnotationsChecker.__classifyError"></a> |
|
232 <h4>AnnotationsChecker.__classifyError</h4> |
|
233 <b>__classifyError</b>(<i>function, arg</i>) |
|
234 |
|
235 <p> |
|
236 Private method to classify the missing type annotation based on the |
|
237 Function & Argument metadata. |
|
238 </p> |
|
239 <p> |
|
240 For the currently defined rules & program flow, the assumption can be |
|
241 made that an argument passed to this method will match a linting error, |
|
242 and will only match a single linting error |
|
243 </p> |
|
244 <p> |
|
245 This function provides an initial classificaton, then passes relevant |
|
246 attributes to cached helper function(s). |
|
247 </p> |
|
248 <dl> |
|
249 |
|
250 <dt><i>function</i> (Function)</dt> |
|
251 <dd> |
|
252 reference to the Function object |
|
253 </dd> |
|
254 <dt><i>arg</i> (Argument)</dt> |
|
255 <dd> |
|
256 reference to the Argument object |
|
257 </dd> |
|
258 </dl> |
181 <a NAME="AnnotationsChecker.__error" ID="AnnotationsChecker.__error"></a> |
259 <a NAME="AnnotationsChecker.__error" ID="AnnotationsChecker.__error"></a> |
182 <h4>AnnotationsChecker.__error</h4> |
260 <h4>AnnotationsChecker.__error</h4> |
183 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
261 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
184 |
262 |
185 <p> |
263 <p> |
202 <dt><i>args</i> (list)</dt> |
280 <dt><i>args</i> (list)</dt> |
203 <dd> |
281 <dd> |
204 arguments for the message |
282 arguments for the message |
205 </dd> |
283 </dd> |
206 </dl> |
284 </dl> |
|
285 <a NAME="AnnotationsChecker.__getAnnotationComplexity" ID="AnnotationsChecker.__getAnnotationComplexity"></a> |
|
286 <h4>AnnotationsChecker.__getAnnotationComplexity</h4> |
|
287 <b>__getAnnotationComplexity</b>(<i>annotationNode, defaultComplexity=1</i>) |
|
288 |
|
289 <p> |
|
290 Private method to determine the annotation complexity. |
|
291 </p> |
|
292 <dl> |
|
293 |
|
294 <dt><i>annotationNode</i> (ast.AST)</dt> |
|
295 <dd> |
|
296 reference to the node to determine the annotation |
|
297 complexity for |
|
298 </dd> |
|
299 <dt><i>defaultComplexity</i> (int)</dt> |
|
300 <dd> |
|
301 default complexity value |
|
302 </dd> |
|
303 </dl> |
|
304 <dl> |
|
305 <dt>Return:</dt> |
|
306 <dd> |
|
307 annotation complexity |
|
308 </dd> |
|
309 </dl> |
|
310 <dl> |
|
311 <dt>Return Type:</dt> |
|
312 <dd> |
|
313 = int |
|
314 </dd> |
|
315 </dl> |
|
316 <a NAME="AnnotationsChecker.__getAnnotationLength" ID="AnnotationsChecker.__getAnnotationLength"></a> |
|
317 <h4>AnnotationsChecker.__getAnnotationLength</h4> |
|
318 <b>__getAnnotationLength</b>(<i>annotationNode</i>) |
|
319 |
|
320 <p> |
|
321 Private method to determine the annotation length. |
|
322 </p> |
|
323 <dl> |
|
324 |
|
325 <dt><i>annotationNode</i> (ast.AST)</dt> |
|
326 <dd> |
|
327 reference to the node to determine the annotation |
|
328 length for |
|
329 </dd> |
|
330 </dl> |
|
331 <dl> |
|
332 <dt>Return:</dt> |
|
333 <dd> |
|
334 annotation length |
|
335 </dd> |
|
336 </dl> |
|
337 <dl> |
|
338 <dt>Return Type:</dt> |
|
339 <dd> |
|
340 = int |
|
341 </dd> |
|
342 </dl> |
|
343 <a NAME="AnnotationsChecker.__hasTypeAnnotations" ID="AnnotationsChecker.__hasTypeAnnotations"></a> |
|
344 <h4>AnnotationsChecker.__hasTypeAnnotations</h4> |
|
345 <b>__hasTypeAnnotations</b>(<i>funcNode</i>) |
|
346 |
|
347 <p> |
|
348 Private method to check for type annotations. |
|
349 </p> |
|
350 <dl> |
|
351 |
|
352 <dt><i>funcNode</i> (ast.AsyncFunctionDef or ast.FunctionDef)</dt> |
|
353 <dd> |
|
354 reference to the function definition node to be checked |
|
355 </dd> |
|
356 </dl> |
|
357 <dl> |
|
358 <dt>Return:</dt> |
|
359 <dd> |
|
360 flag indicating the presence of type annotations |
|
361 </dd> |
|
362 </dl> |
|
363 <dl> |
|
364 <dt>Return Type:</dt> |
|
365 <dd> |
|
366 bool |
|
367 </dd> |
|
368 </dl> |
207 <a NAME="AnnotationsChecker.__ignoreCode" ID="AnnotationsChecker.__ignoreCode"></a> |
369 <a NAME="AnnotationsChecker.__ignoreCode" ID="AnnotationsChecker.__ignoreCode"></a> |
208 <h4>AnnotationsChecker.__ignoreCode</h4> |
370 <h4>AnnotationsChecker.__ignoreCode</h4> |
209 <b>__ignoreCode</b>(<i>code</i>) |
371 <b>__ignoreCode</b>(<i>code</i>) |
210 |
372 |
211 <p> |
373 <p> |
228 <dt>Return Type:</dt> |
390 <dt>Return Type:</dt> |
229 <dd> |
391 <dd> |
230 bool |
392 bool |
231 </dd> |
393 </dd> |
232 </dl> |
394 </dl> |
|
395 <a NAME="AnnotationsChecker.__returnErrorClassifier" ID="AnnotationsChecker.__returnErrorClassifier"></a> |
|
396 <h4>AnnotationsChecker.__returnErrorClassifier</h4> |
|
397 <b>__returnErrorClassifier</b>(<i>isClassMethod, classDecoratorType, functionType</i>) |
|
398 |
|
399 <p> |
|
400 Private method to classify a return type annotation issue. |
|
401 </p> |
|
402 <dl> |
|
403 |
|
404 <dt><i>isClassMethod</i> (bool)</dt> |
|
405 <dd> |
|
406 flag indicating a classmethod type function |
|
407 </dd> |
|
408 <dt><i>classDecoratorType</i> (ClassDecoratorType)</dt> |
|
409 <dd> |
|
410 type of class decorator |
|
411 </dd> |
|
412 <dt><i>functionType</i> (FunctionType)</dt> |
|
413 <dd> |
|
414 type of function |
|
415 </dd> |
|
416 </dl> |
|
417 <dl> |
|
418 <dt>Return:</dt> |
|
419 <dd> |
|
420 error code |
|
421 </dd> |
|
422 </dl> |
|
423 <dl> |
|
424 <dt>Return Type:</dt> |
|
425 <dd> |
|
426 str |
|
427 </dd> |
|
428 </dl> |
233 <a NAME="AnnotationsChecker.run" ID="AnnotationsChecker.run"></a> |
429 <a NAME="AnnotationsChecker.run" ID="AnnotationsChecker.run"></a> |
234 <h4>AnnotationsChecker.run</h4> |
430 <h4>AnnotationsChecker.run</h4> |
235 <b>run</b>(<i></i>) |
431 <b>run</b>(<i></i>) |
236 |
432 |
237 <p> |
433 <p> |
238 Public method to check the given source against annotation issues. |
434 Public method to check the given source against annotation issues. |
239 </p> |
435 </p> |
240 <div align="right"><a href="#top">Up</a></div> |
436 <div align="right"><a href="#top">Up</a></div> |
241 <hr /> |
437 <hr /> |
242 <hr /> |
|
243 <a NAME="FunctionVisitor" ID="FunctionVisitor"></a> |
|
244 <h2>FunctionVisitor</h2> |
|
245 |
|
246 <p> |
|
247 Class implementing a node visitor to check function annotations. |
|
248 </p> |
|
249 <p> |
|
250 Note: this class is modelled after flake8-annotations checker. |
|
251 </p> |
|
252 <h3>Derived from</h3> |
|
253 ast.NodeVisitor |
|
254 <h3>Class Attributes</h3> |
|
255 |
|
256 <table> |
|
257 <tr><td>None</td></tr> |
|
258 </table> |
|
259 <h3>Class Methods</h3> |
|
260 |
|
261 <table> |
|
262 <tr><td>None</td></tr> |
|
263 </table> |
|
264 <h3>Methods</h3> |
|
265 |
|
266 <table> |
|
267 |
|
268 <tr> |
|
269 <td><a href="#FunctionVisitor.__init__">FunctionVisitor</a></td> |
|
270 <td>Constructor</td> |
|
271 </tr> |
|
272 <tr> |
|
273 <td><a href="#FunctionVisitor.__checkFunctionNode">__checkFunctionNode</a></td> |
|
274 <td>Private method to check an individual function definition node.</td> |
|
275 </tr> |
|
276 <tr> |
|
277 <td><a href="#FunctionVisitor.__classifyArgumentError">__classifyArgumentError</a></td> |
|
278 <td>Private method to classify and record an argument annotation issue.</td> |
|
279 </tr> |
|
280 <tr> |
|
281 <td><a href="#FunctionVisitor.__classifyReturnError">__classifyReturnError</a></td> |
|
282 <td>Private method to classify and record a return annotation issue.</td> |
|
283 </tr> |
|
284 <tr> |
|
285 <td><a href="#FunctionVisitor.visit_AsyncFunctionDef">visit_AsyncFunctionDef</a></td> |
|
286 <td>Public method to handle an async function or method definition.</td> |
|
287 </tr> |
|
288 <tr> |
|
289 <td><a href="#FunctionVisitor.visit_ClassDef">visit_ClassDef</a></td> |
|
290 <td>Public method to handle class definitions.</td> |
|
291 </tr> |
|
292 <tr> |
|
293 <td><a href="#FunctionVisitor.visit_FunctionDef">visit_FunctionDef</a></td> |
|
294 <td>Public method to handle a function or method definition.</td> |
|
295 </tr> |
|
296 </table> |
|
297 <h3>Static Methods</h3> |
|
298 |
|
299 <table> |
|
300 <tr><td>None</td></tr> |
|
301 </table> |
|
302 |
|
303 <a NAME="FunctionVisitor.__init__" ID="FunctionVisitor.__init__"></a> |
|
304 <h4>FunctionVisitor (Constructor)</h4> |
|
305 <b>FunctionVisitor</b>(<i>sourceLines</i>) |
|
306 |
|
307 <p> |
|
308 Constructor |
|
309 </p> |
|
310 <dl> |
|
311 |
|
312 <dt><i>sourceLines</i> (list of str)</dt> |
|
313 <dd> |
|
314 lines of source code |
|
315 </dd> |
|
316 </dl> |
|
317 <a NAME="FunctionVisitor.__checkFunctionNode" ID="FunctionVisitor.__checkFunctionNode"></a> |
|
318 <h4>FunctionVisitor.__checkFunctionNode</h4> |
|
319 <b>__checkFunctionNode</b>(<i>node, classMethod=False</i>) |
|
320 |
|
321 <p> |
|
322 Private method to check an individual function definition node. |
|
323 </p> |
|
324 <dl> |
|
325 |
|
326 <dt><i>node</i> (ast.FunctionDef or ast.AsyncFunctionDef)</dt> |
|
327 <dd> |
|
328 reference to the node to be processed |
|
329 </dd> |
|
330 <dt><i>classMethod</i> (bool)</dt> |
|
331 <dd> |
|
332 flag indicating a class method |
|
333 </dd> |
|
334 </dl> |
|
335 <a NAME="FunctionVisitor.__classifyArgumentError" ID="FunctionVisitor.__classifyArgumentError"></a> |
|
336 <h4>FunctionVisitor.__classifyArgumentError</h4> |
|
337 <b>__classifyArgumentError</b>(<i>argNode, argType, methodType</i>) |
|
338 |
|
339 <p> |
|
340 Private method to classify and record an argument annotation issue. |
|
341 </p> |
|
342 <dl> |
|
343 |
|
344 <dt><i>argNode</i> (ast.arguments)</dt> |
|
345 <dd> |
|
346 reference to the argument node |
|
347 </dd> |
|
348 <dt><i>argType</i> (str)</dt> |
|
349 <dd> |
|
350 type of the argument node |
|
351 </dd> |
|
352 <dt><i>methodType</i> (str)</dt> |
|
353 <dd> |
|
354 type of method/function the argument belongs to |
|
355 </dd> |
|
356 </dl> |
|
357 <a NAME="FunctionVisitor.__classifyReturnError" ID="FunctionVisitor.__classifyReturnError"></a> |
|
358 <h4>FunctionVisitor.__classifyReturnError</h4> |
|
359 <b>__classifyReturnError</b>(<i>methodType, visibilityType, lineno, colOffset</i>) |
|
360 |
|
361 <p> |
|
362 Private method to classify and record a return annotation issue. |
|
363 </p> |
|
364 <dl> |
|
365 |
|
366 <dt><i>methodType</i> (str)</dt> |
|
367 <dd> |
|
368 type of method/function the argument belongs to |
|
369 </dd> |
|
370 <dt><i>visibilityType</i> (str)</dt> |
|
371 <dd> |
|
372 visibility of the function |
|
373 </dd> |
|
374 <dt><i>lineno</i> (int)</dt> |
|
375 <dd> |
|
376 line number |
|
377 </dd> |
|
378 <dt><i>colOffset</i> (int)</dt> |
|
379 <dd> |
|
380 column number |
|
381 </dd> |
|
382 </dl> |
|
383 <a NAME="FunctionVisitor.visit_AsyncFunctionDef" ID="FunctionVisitor.visit_AsyncFunctionDef"></a> |
|
384 <h4>FunctionVisitor.visit_AsyncFunctionDef</h4> |
|
385 <b>visit_AsyncFunctionDef</b>(<i>node</i>) |
|
386 |
|
387 <p> |
|
388 Public method to handle an async function or method definition. |
|
389 </p> |
|
390 <dl> |
|
391 |
|
392 <dt><i>node</i> (ast.AsyncFunctionDef)</dt> |
|
393 <dd> |
|
394 reference to the node to be processed |
|
395 </dd> |
|
396 </dl> |
|
397 <a NAME="FunctionVisitor.visit_ClassDef" ID="FunctionVisitor.visit_ClassDef"></a> |
|
398 <h4>FunctionVisitor.visit_ClassDef</h4> |
|
399 <b>visit_ClassDef</b>(<i>node</i>) |
|
400 |
|
401 <p> |
|
402 Public method to handle class definitions. |
|
403 </p> |
|
404 <dl> |
|
405 |
|
406 <dt><i>node</i> (ast.ClassDef)</dt> |
|
407 <dd> |
|
408 reference to the node to be processed |
|
409 </dd> |
|
410 </dl> |
|
411 <a NAME="FunctionVisitor.visit_FunctionDef" ID="FunctionVisitor.visit_FunctionDef"></a> |
|
412 <h4>FunctionVisitor.visit_FunctionDef</h4> |
|
413 <b>visit_FunctionDef</b>(<i>node</i>) |
|
414 |
|
415 <p> |
|
416 Public method to handle a function or method definition. |
|
417 </p> |
|
418 <dl> |
|
419 |
|
420 <dt><i>node</i> (ast.FunctionDef)</dt> |
|
421 <dd> |
|
422 reference to the node to be processed |
|
423 </dd> |
|
424 </dl> |
|
425 <div align="right"><a href="#top">Up</a></div> |
|
426 <hr /> |
|
427 <hr /> |
|
428 <a NAME="getAnnotationComplexity" ID="getAnnotationComplexity"></a> |
|
429 <h2>getAnnotationComplexity</h2> |
|
430 <b>getAnnotationComplexity</b>(<i>annotationNode</i>) |
|
431 |
|
432 <p> |
|
433 Function to determine the annotation complexity. |
|
434 </p> |
|
435 <dl> |
|
436 |
|
437 <dt><i>annotationNode</i> (ast.AST)</dt> |
|
438 <dd> |
|
439 reference to the node to determine the annotation |
|
440 complexity for |
|
441 </dd> |
|
442 </dl> |
|
443 <dl> |
|
444 <dt>Return:</dt> |
|
445 <dd> |
|
446 annotation complexity |
|
447 </dd> |
|
448 </dl> |
|
449 <dl> |
|
450 <dt>Return Type:</dt> |
|
451 <dd> |
|
452 = int |
|
453 </dd> |
|
454 </dl> |
|
455 <div align="right"><a href="#top">Up</a></div> |
|
456 <hr /> |
|
457 <hr /> |
|
458 <a NAME="hasTypeAnnotations" ID="hasTypeAnnotations"></a> |
|
459 <h2>hasTypeAnnotations</h2> |
|
460 <b>hasTypeAnnotations</b>(<i>funcNode</i>) |
|
461 |
|
462 <p> |
|
463 Function to check for type annotations. |
|
464 </p> |
|
465 <dl> |
|
466 |
|
467 <dt><i>funcNode</i> (ast.AsyncFunctionDef or ast.FunctionDef)</dt> |
|
468 <dd> |
|
469 reference to the function definition node to be checked |
|
470 </dd> |
|
471 </dl> |
|
472 <dl> |
|
473 <dt>Return:</dt> |
|
474 <dd> |
|
475 flag indicating the presence of type annotations |
|
476 </dd> |
|
477 </dl> |
|
478 <dl> |
|
479 <dt>Return Type:</dt> |
|
480 <dd> |
|
481 bool |
|
482 </dd> |
|
483 </dl> |
|
484 <div align="right"><a href="#top">Up</a></div> |
|
485 <hr /> |
|
486 </body></html> |
438 </body></html> |