# eric6.Plugins.CheckerPlugins.CodeStyleChecker.Annotations.AnnotationsChecker

Module implementing a checker for function type annotations.

### Global Attributes

None

### Classes

AnnotationsChecker | Class implementing a checker for function type annotations.
FunctionVisitor | Class implementing a node visitor to check function annotations.

### Functions

getAnnotationComplexity | Function to determine the annotation complexity.
hasTypeAnnotations | Function to check for type annotations.

## AnnotationsChecker

Class implementing a checker for function type annotations.

### Derived from

object

### Class Attributes

Codes

### Class Methods

None

### Methods

AnnotationsChecker | Constructor
__checkAnnotationComplexity | Private method to check the type annotation complexity.
__checkAnnotationsCoverage | Private method to check for function annotation coverage.
__checkFunctionAnnotations | Private method to check for function annotation issues.
__error | Private method to record an issue.
__generateTree | Private method to generate an AST for our source.
__ignoreCode | Private method to check if the message code should be ignored.
__reportInvalidSyntax | Private method to report a syntax error.
run | Public method to check the given source against annotation issues.

### Static Methods

None

#### AnnotationsChecker (Constructor)

AnnotationsChecker(source, filename, select, ignore, expected, repeat, args)

Constructor

source (list of str)
  source code to be checked
filename (str)
  name of the source file
select (list of str)
  list of selected codes
ignore (list of str)
  list of codes to be ignored
expected (list of str)
  list of expected codes
repeat (bool)
  flag indicating to report each occurrence of a code
args (dict)
  dictionary of arguments for the annotation checks

#### AnnotationsChecker.__checkAnnotationComplexity

__checkAnnotationComplexity()

Private method to check the type annotation complexity.

#### AnnotationsChecker.__checkAnnotationsCoverage

__checkAnnotationsCoverage()

Private method to check for function annotation coverage.

#### AnnotationsChecker.__checkFunctionAnnotations

__checkFunctionAnnotations()

Private method to check for function annotation issues.

#### AnnotationsChecker.__error

__error(lineNumber, offset, code, *args)

Private method to record an issue.

lineNumber (int)
  line number of the issue
offset (int)
  position within line of the issue
code (str)
  message code
args (list)
  arguments for the message

#### AnnotationsChecker.__generateTree

__generateTree()

Private method to generate an AST for our source.

Returns:
  generated AST

Return Type:
  ast.Module

#### AnnotationsChecker.__ignoreCode

__ignoreCode(code)

Private method to check if the message code should be ignored.

code (str)
  message code to check for

Returns:
  flag indicating to ignore the given code

Return Type:
  bool

#### AnnotationsChecker.__reportInvalidSyntax

__reportInvalidSyntax()

Private method to report a syntax error.

#### AnnotationsChecker.run

run()

Public method to check the given source against annotation issues.

Up

## FunctionVisitor

Class implementing a node visitor to check function annotations.

Note: this class is modelled after flake8-annotations checker.

### Derived from

ast.NodeVisitor

### Class Attributes

None

### Class Methods

None

### Methods

FunctionVisitor | Constructor
__checkFunctionNode | Private method to check an individual function definition node.
__classifyArgumentError | Private method to classify and record an argument annotation issue.
__classifyReturnError | Private method to classify and record a return annotation issue.
visit_AsyncFunctionDef | Public method to handle an async function or method definition.
visit_ClassDef | Public method to handle class definitions.
visit_FunctionDef | Public method to handle a function or method definition.

### Static Methods

None

#### FunctionVisitor (Constructor)

FunctionVisitor(sourceLines)

Constructor

sourceLines (list of str)
  lines of source code

#### FunctionVisitor.__checkFunctionNode

__checkFunctionNode(node, classMethod=False)

Private method to check an individual function definition node.

node (ast.FunctionDef or ast.AsyncFunctionDef)
  reference to the node to be processed
classMethod (bool)
  flag indicating a class method

#### FunctionVisitor.__classifyArgumentError

__classifyArgumentError(argNode, argType, methodType)

Private method to classify and record an argument annotation issue.

argNode (ast.arguments)
  reference to the argument node
argType (str)
  type of the argument node
methodType (str)
  type of method/function the argument belongs to

#### FunctionVisitor.__classifyReturnError

__classifyReturnError(methodType, visibilityType, lineno, colOffset)

Private method to classify and record a return annotation issue.

methodType (str)
  type of method/function the argument belongs to
visibilityType (str)
  visibility of the function
lineno (int)
  line number
colOffset (int)
  column number

#### FunctionVisitor.visit_AsyncFunctionDef

visit_AsyncFunctionDef(node)

Public method to handle an async function or method definition.

node (ast.AsyncFunctionDef)
  reference to the node to be processed

#### FunctionVisitor.visit_ClassDef

visit_ClassDef(node)

Public method to handle class definitions.

node (ast.ClassDef)
  reference to the node to be processed

#### FunctionVisitor.visit_FunctionDef

visit_FunctionDef(node)

Public method to handle a function or method definition.

node (ast.FunctionDef)
  reference to the node to be processed

Up

## getAnnotationComplexity

getAnnotationComplexity(annotationNode)

Function to determine the annotation complexity.

annotationNode (ast.AST)
  reference to the node to determine the annotation complexity for

Returns:
  annotation complexity

Return Type:
  = int

Up

## hasTypeAnnotations

hasTypeAnnotations(funcNode)

Function to check for type annotations.

funcNode (ast.AsyncFunctionDef or ast.FunctionDef)
  reference to the function definition node to be checked

Returns:
  flag indicating the presence of type annotations

Return Type:
  bool

Up