# eric7.Plugins.CheckerPlugins.CodeStyleChecker.Imports.ImportsChecker

Module implementing a checker for import statements.

### Global Attributes

None

### Classes

ImportsChecker | Class implementing a checker for import statements.

### Functions

None

## ImportsChecker

Class implementing a checker for import statements.

### Derived from

None

### Class Attributes

Codes

### Class Methods

None

### Methods

ImportsChecker | Constructor
__checkBannedImport | Private method to check import of banned modules.
__checkBannedRelativeImports | Private method to check if relative imports are banned.
__checkImportOrder | Private method to check the order of import statements.
__checkLocalImports | Private method to check local imports.
__checkUnnecessaryAlias | Private method to check unnecessary import aliases.
__error | Private method to record an issue.
__findErrorInAll | Private method to check the '__all__' node for errors.
__findNodes | Private method to find all import and import from nodes of the given tree.
__ignoreCode | Private method to check if the message code should be ignored.
__tidyImports | Private method to check various other import related topics.
getStandardModules | Public method to get a list of modules of the standard library.
run | Public method to check the given source against miscellaneous conditions.

### Static Methods

None

#### ImportsChecker (Constructor)

ImportsChecker(source, filename, tree, select, ignore, expected, repeat, args)

Constructor

source (list of str)
  source code to be checked
filename (str)
  name of the source file
tree (ast.Module)
  AST tree of the source code
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 various checks

#### ImportsChecker.__checkBannedImport

__checkBannedImport(node)

Private method to check import of banned modules.

node (ast.AST)
  reference to the node to be checked

#### ImportsChecker.__checkBannedRelativeImports

__checkBannedRelativeImports(node)

Private method to check if relative imports are banned.

node (ast.AST)
  reference to the node to be checked

#### ImportsChecker.__checkImportOrder

__checkImportOrder()

Private method to check the order of import statements.

#### ImportsChecker.__checkLocalImports

__checkLocalImports()

Private method to check local imports.

#### ImportsChecker.__checkUnnecessaryAlias

__checkUnnecessaryAlias(node)

Private method to check unnecessary import aliases.

node (ast.AST)
  reference to the node to be checked

#### ImportsChecker.__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

#### ImportsChecker.__findErrorInAll

__findErrorInAll(node)

Private method to check the '__all__' node for errors.

node (ast.List or ast.Tuple)
  reference to the '__all__' node

Return:
  tuple containing a reference to the node and an error code

Return Type:
  rtype tuple of (ast.List | ast.Tuple, str)

#### ImportsChecker.__findNodes

__findNodes(tree)

Private method to find all import and import from nodes of the given tree.

tree (ast.AST)
  reference to the ast node tree to be parsed

Return:
  tuple containing a list of import nodes and the '__all__' node

Return Type:
  tuple of (ast.Import | ast.ImportFrom, ast.List | ast.Tuple)

#### ImportsChecker.__ignoreCode

__ignoreCode(code)

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

code (str)
  message code to check for

Return:
  flag indicating to ignore the given code

Return Type:
  bool

#### ImportsChecker.__tidyImports

__tidyImports()

Private method to check various other import related topics.

#### ImportsChecker.getStandardModules

getStandardModules()

Public method to get a list of modules of the standard library.

Return:
  set of builtin modules

Return Type:
  set of str

#### ImportsChecker.run

run()

Public method to check the given source against miscellaneous conditions.

Up