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
__atoi Private method to convert the given text to an integer number.
__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.
__compileUnstructuredGlob Private method to convert a pattern to a regex such that ".*" matches zero or more modules.
__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.
__isModuleBanned Private method to check, if the given module name banned.
__naturalKeys Private method to generate keys for natural sorting.
__naturally Private method to sort the given list of names naturally.
__tidyImports Private method to check various other import related topics.
getStandardModules Public method to get a list of modules of the standard library.
keyCallback
moduleKey Public method to generate a key for the given module name.
run Public method to check the given source against miscellaneous conditions.
sorted Public method to sort the given list of names.

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.__atoi

__atoi(text)

Private method to convert the given text to an integer number.

text (str)
text to be converted
Return:
integer number
Return Type:
int

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.__compileUnstructuredGlob

__compileUnstructuredGlob(module)

Private method to convert a pattern to a regex such that ".*" matches zero or more modules.

module (str)
module pattern to be converted
Return:
compiled regex
Return Type:
re.regex object

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.__isModuleBanned

__isModuleBanned(moduleName)

Private method to check, if the given module name banned.

moduleName (str)
module name to be checked
Return:
flag indicating a banned module
Return Type:
bool

ImportsChecker.__naturalKeys

__naturalKeys(text)

Private method to generate keys for natural sorting.

text (str)
text to generate a key for
Return:
key for natural sorting
Return Type:
list of str or int

ImportsChecker.__naturally

__naturally(toSort, key=None, reverse=False)

Private method to sort the given list of names naturally.

Note: Natural sorting maintains the sort order of numbers (i.e. [Q1, Q10, Q2] is sorted as [Q1, Q2, Q10] while the Python standard sort would yield [Q1, Q10, Q2].

toSort (list of str)
list of names to be sorted
key (function (optional))
function to generate keys (defaults to None)
reverse (bool (optional))
flag indicating a reverse sort (defaults to False)
Return:
sorted list of names
Return Type:
list of str

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.keyCallback

keyCallback()

ImportsChecker.moduleKey

moduleKey(moduleName, subImports=False)

Public method to generate a key for the given module name.

moduleName (str)
module name
subImports (bool (optional))
flag indicating a sub import like in 'from foo import bar, baz' (defaults to False)
Return:
generated key
Return Type:
str

ImportsChecker.run

run()

Public method to check the given source against miscellaneous conditions.

ImportsChecker.sorted

sorted(toSort, key=None, reverse=False)

Public method to sort the given list of names.

toSort (list of str)
list of names to be sorted
key (function (optional))
function to generate keys (defaults to None)
reverse (bool (optional))
flag indicating a reverse sort (defaults to False)
Return:
sorted list of names
Return Type:
list of str
Up