src/eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Imports.ImportsChecker.html

Thu, 07 Jul 2022 11:23:56 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Thu, 07 Jul 2022 11:23:56 +0200
branch
eric7
changeset 9209
b99e7fd55fd3
parent 8877
eric7/Documentation/Source/eric7.Plugins.CheckerPlugins.CodeStyleChecker.Imports.ImportsChecker.html@548d45c3f571
child 9295
d14096c04126
permissions
-rw-r--r--

Reorganized the project structure to use the source layout in order to support up-to-date build systems with "pyproject.toml".

<!DOCTYPE html>
<html><head>
<title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Imports.ImportsChecker</title>
<meta charset="UTF-8">
<link rel="stylesheet" href="styles.css">
</head>
<body>
<a NAME="top" ID="top"></a>
<h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Imports.ImportsChecker</h1>

<p>
Module implementing a checker for import statements.
</p>
<h3>Global Attributes</h3>

<table>
<tr><td>None</td></tr>
</table>
<h3>Classes</h3>

<table>

<tr>
<td><a href="#ImportsChecker">ImportsChecker</a></td>
<td>Class implementing a checker for import statements.</td>
</tr>
</table>
<h3>Functions</h3>

<table>
<tr><td>None</td></tr>
</table>
<hr />
<hr />
<a NAME="ImportsChecker" ID="ImportsChecker"></a>
<h2>ImportsChecker</h2>

<p>
    Class implementing a checker for import statements.
</p>
<h3>Derived from</h3>
None
<h3>Class Attributes</h3>

<table>
<tr><td>Codes</td></tr>
</table>
<h3>Class Methods</h3>

<table>
<tr><td>None</td></tr>
</table>
<h3>Methods</h3>

<table>

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

<table>
<tr><td>None</td></tr>
</table>

<a NAME="ImportsChecker.__init__" ID="ImportsChecker.__init__"></a>
<h4>ImportsChecker (Constructor)</h4>
<b>ImportsChecker</b>(<i>source, filename, tree, select, ignore, expected, repeat, args</i>)

<p>
        Constructor
</p>
<dl>

<dt><i>source</i> (list of str)</dt>
<dd>
source code to be checked
</dd>
<dt><i>filename</i> (str)</dt>
<dd>
name of the source file
</dd>
<dt><i>tree</i> (ast.Module)</dt>
<dd>
AST tree of the source code
</dd>
<dt><i>select</i> (list of str)</dt>
<dd>
list of selected codes
</dd>
<dt><i>ignore</i> (list of str)</dt>
<dd>
list of codes to be ignored
</dd>
<dt><i>expected</i> (list of str)</dt>
<dd>
list of expected codes
</dd>
<dt><i>repeat</i> (bool)</dt>
<dd>
flag indicating to report each occurrence of a code
</dd>
<dt><i>args</i> (dict)</dt>
<dd>
dictionary of arguments for the various checks
</dd>
</dl>
<a NAME="ImportsChecker.__checkBannedImport" ID="ImportsChecker.__checkBannedImport"></a>
<h4>ImportsChecker.__checkBannedImport</h4>
<b>__checkBannedImport</b>(<i>node</i>)

<p>
        Private method to check import of banned modules.
</p>
<dl>

<dt><i>node</i> (ast.AST)</dt>
<dd>
reference to the node to be checked
</dd>
</dl>
<a NAME="ImportsChecker.__checkBannedRelativeImports" ID="ImportsChecker.__checkBannedRelativeImports"></a>
<h4>ImportsChecker.__checkBannedRelativeImports</h4>
<b>__checkBannedRelativeImports</b>(<i>node</i>)

<p>
        Private method to check if relative imports are banned.
</p>
<dl>

<dt><i>node</i> (ast.AST)</dt>
<dd>
reference to the node to be checked
</dd>
</dl>
<a NAME="ImportsChecker.__checkImportOrder" ID="ImportsChecker.__checkImportOrder"></a>
<h4>ImportsChecker.__checkImportOrder</h4>
<b>__checkImportOrder</b>(<i></i>)

<p>
        Private method to check the order of import statements.
</p>
<a NAME="ImportsChecker.__checkLocalImports" ID="ImportsChecker.__checkLocalImports"></a>
<h4>ImportsChecker.__checkLocalImports</h4>
<b>__checkLocalImports</b>(<i></i>)

<p>
        Private method to check local imports.
</p>
<a NAME="ImportsChecker.__checkUnnecessaryAlias" ID="ImportsChecker.__checkUnnecessaryAlias"></a>
<h4>ImportsChecker.__checkUnnecessaryAlias</h4>
<b>__checkUnnecessaryAlias</b>(<i>node</i>)

<p>
        Private method to check unnecessary import aliases.
</p>
<dl>

<dt><i>node</i> (ast.AST)</dt>
<dd>
reference to the node to be checked
</dd>
</dl>
<a NAME="ImportsChecker.__error" ID="ImportsChecker.__error"></a>
<h4>ImportsChecker.__error</h4>
<b>__error</b>(<i>lineNumber, offset, code, *args</i>)

<p>
        Private method to record an issue.
</p>
<dl>

<dt><i>lineNumber</i> (int)</dt>
<dd>
line number of the issue
</dd>
<dt><i>offset</i> (int)</dt>
<dd>
position within line of the issue
</dd>
<dt><i>code</i> (str)</dt>
<dd>
message code
</dd>
<dt><i>args</i> (list)</dt>
<dd>
arguments for the message
</dd>
</dl>
<a NAME="ImportsChecker.__findErrorInAll" ID="ImportsChecker.__findErrorInAll"></a>
<h4>ImportsChecker.__findErrorInAll</h4>
<b>__findErrorInAll</b>(<i>node</i>)

<p>
        Private method to check the '__all__' node for errors.
</p>
<dl>

<dt><i>node</i> (ast.List or ast.Tuple)</dt>
<dd>
reference to the '__all__' node
</dd>
</dl>
<dl>
<dt>Return:</dt>
<dd>
tuple containing a reference to the node and an error code
</dd>
</dl>
<dl>
<dt>Return Type:</dt>
<dd>
rtype tuple of (ast.List | ast.Tuple, str)
</dd>
</dl>
<a NAME="ImportsChecker.__findNodes" ID="ImportsChecker.__findNodes"></a>
<h4>ImportsChecker.__findNodes</h4>
<b>__findNodes</b>(<i>tree</i>)

<p>
        Private method to find all import and import from nodes of the given
        tree.
</p>
<dl>

<dt><i>tree</i> (ast.AST)</dt>
<dd>
reference to the ast node tree to be parsed
</dd>
</dl>
<dl>
<dt>Return:</dt>
<dd>
tuple containing a list of import nodes and the '__all__' node
</dd>
</dl>
<dl>
<dt>Return Type:</dt>
<dd>
tuple of (ast.Import | ast.ImportFrom, ast.List | ast.Tuple)
</dd>
</dl>
<a NAME="ImportsChecker.__ignoreCode" ID="ImportsChecker.__ignoreCode"></a>
<h4>ImportsChecker.__ignoreCode</h4>
<b>__ignoreCode</b>(<i>code</i>)

<p>
        Private method to check if the message code should be ignored.
</p>
<dl>

<dt><i>code</i> (str)</dt>
<dd>
message code to check for
</dd>
</dl>
<dl>
<dt>Return:</dt>
<dd>
flag indicating to ignore the given code
</dd>
</dl>
<dl>
<dt>Return Type:</dt>
<dd>
bool
</dd>
</dl>
<a NAME="ImportsChecker.__tidyImports" ID="ImportsChecker.__tidyImports"></a>
<h4>ImportsChecker.__tidyImports</h4>
<b>__tidyImports</b>(<i></i>)

<p>
        Private method to check various other import related topics.
</p>
<a NAME="ImportsChecker.getStandardModules" ID="ImportsChecker.getStandardModules"></a>
<h4>ImportsChecker.getStandardModules</h4>
<b>getStandardModules</b>(<i></i>)

<p>
        Public method to get a list of modules of the standard library.
</p>
<dl>
<dt>Return:</dt>
<dd>
set of builtin modules
</dd>
</dl>
<dl>
<dt>Return Type:</dt>
<dd>
set of str
</dd>
</dl>
<a NAME="ImportsChecker.run" ID="ImportsChecker.run"></a>
<h4>ImportsChecker.run</h4>
<b>run</b>(<i></i>)

<p>
        Public method to check the given source against miscellaneous
        conditions.
</p>
<div align="right"><a href="#top">Up</a></div>
<hr />
</body></html>

eric ide

mercurial