eric7.Plugins.CheckerPlugins.CodeStyleChecker.NameOrder.NameOrderChecker
Module implementing a checker for import statements.
Global Attributes
Classes
Functions
NameOrderChecker
Class implementing a checker for name ordering.
Note: Name ordering is checked for import statements, the '__all__' statement
and exception names of exception handlers.
Derived from
None
Class Attributes
Class Methods
Methods
NameOrderChecker |
Constructor |
__atoi |
Private method to convert the given text to an integer number. |
__checkNameOrder |
Private method to check the order of import statements and handled exceptions. |
__error |
Private method to record an issue. |
__findErrorInAll |
Private method to check the '__all__' node for errors. |
__findExceptionListErrors |
Private method to check the exception node for errors. |
__findExceptionListNodes |
Private method to find all exception types handled by given tree. |
__findExceptionListStr |
Private method to get the exception name out of an exception handler type node. |
__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. |
__naturalKeys |
Private method to generate keys for natural sorting. |
__naturally |
Private method to sort the given list of names naturally. |
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
NameOrderChecker (Constructor)
NameOrderChecker(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
NameOrderChecker.__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
NameOrderChecker.__checkNameOrder
__checkNameOrder()
Private method to check the order of import statements and handled exceptions.
NameOrderChecker.__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
NameOrderChecker.__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 an error code and the error
arguments
- Return Type:
-
tuple of (ast.List | ast.Tuple, str, str)
NameOrderChecker.__findExceptionListErrors
__findExceptionListErrors(nodes)
Private method to check the exception node for errors.
- nodes (list of ast.List or ast.Tuple)
-
list of exception nodes
- Return:
-
DESCRIPTION
- Return Type:
-
TYPE
NameOrderChecker.__findExceptionListNodes
__findExceptionListNodes(tree)
Private method to find all exception types handled by given tree.
- tree (ast.AST)
-
reference to the ast node tree to be parsed
- Return:
-
list of exception types
- Return Type:
-
list of ast.Name
NameOrderChecker.__findExceptionListStr
__findExceptionListStr(node)
Private method to get the exception name out of an exception handler type node.
- node (ast.Name or ast.Attribute)
-
node to be treated
- Return:
-
string containing the exception name
- Return Type:
-
str
NameOrderChecker.__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, the '__all__' node and
exception nodes
- Return Type:
-
tuple of (ast.Import | ast.ImportFrom, ast.List | ast.Tuple,
ast.List | ast.Tuple)
NameOrderChecker.__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
NameOrderChecker.__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
NameOrderChecker.__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
NameOrderChecker.keyCallback
keyCallback()
NameOrderChecker.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
NameOrderChecker.run
run()
Public method to check the given source against miscellaneous
conditions.
NameOrderChecker.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