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

branch
eric7
changeset 8877
548d45c3f571
equal deleted inserted replaced
8876:2001accf55b3 8877:548d45c3f571
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Imports.ImportsChecker</title>
4 <meta charset="UTF-8">
5 <link rel="stylesheet" href="styles.css">
6 </head>
7 <body>
8 <a NAME="top" ID="top"></a>
9 <h1>eric7.Plugins.CheckerPlugins.CodeStyleChecker.Imports.ImportsChecker</h1>
10
11 <p>
12 Module implementing a checker for import statements.
13 </p>
14 <h3>Global Attributes</h3>
15
16 <table>
17 <tr><td>None</td></tr>
18 </table>
19 <h3>Classes</h3>
20
21 <table>
22
23 <tr>
24 <td><a href="#ImportsChecker">ImportsChecker</a></td>
25 <td>Class implementing a checker for import statements.</td>
26 </tr>
27 </table>
28 <h3>Functions</h3>
29
30 <table>
31 <tr><td>None</td></tr>
32 </table>
33 <hr />
34 <hr />
35 <a NAME="ImportsChecker" ID="ImportsChecker"></a>
36 <h2>ImportsChecker</h2>
37
38 <p>
39 Class implementing a checker for import statements.
40 </p>
41 <h3>Derived from</h3>
42 None
43 <h3>Class Attributes</h3>
44
45 <table>
46 <tr><td>Codes</td></tr>
47 </table>
48 <h3>Class Methods</h3>
49
50 <table>
51 <tr><td>None</td></tr>
52 </table>
53 <h3>Methods</h3>
54
55 <table>
56
57 <tr>
58 <td><a href="#ImportsChecker.__init__">ImportsChecker</a></td>
59 <td>Constructor</td>
60 </tr>
61 <tr>
62 <td><a href="#ImportsChecker.__checkBannedImport">__checkBannedImport</a></td>
63 <td>Private method to check import of banned modules.</td>
64 </tr>
65 <tr>
66 <td><a href="#ImportsChecker.__checkBannedRelativeImports">__checkBannedRelativeImports</a></td>
67 <td>Private method to check if relative imports are banned.</td>
68 </tr>
69 <tr>
70 <td><a href="#ImportsChecker.__checkImportOrder">__checkImportOrder</a></td>
71 <td>Private method to check the order of import statements.</td>
72 </tr>
73 <tr>
74 <td><a href="#ImportsChecker.__checkLocalImports">__checkLocalImports</a></td>
75 <td>Private method to check local imports.</td>
76 </tr>
77 <tr>
78 <td><a href="#ImportsChecker.__checkUnnecessaryAlias">__checkUnnecessaryAlias</a></td>
79 <td>Private method to check unnecessary import aliases.</td>
80 </tr>
81 <tr>
82 <td><a href="#ImportsChecker.__error">__error</a></td>
83 <td>Private method to record an issue.</td>
84 </tr>
85 <tr>
86 <td><a href="#ImportsChecker.__findErrorInAll">__findErrorInAll</a></td>
87 <td>Private method to check the '__all__' node for errors.</td>
88 </tr>
89 <tr>
90 <td><a href="#ImportsChecker.__findNodes">__findNodes</a></td>
91 <td>Private method to find all import and import from nodes of the given tree.</td>
92 </tr>
93 <tr>
94 <td><a href="#ImportsChecker.__ignoreCode">__ignoreCode</a></td>
95 <td>Private method to check if the message code should be ignored.</td>
96 </tr>
97 <tr>
98 <td><a href="#ImportsChecker.__tidyImports">__tidyImports</a></td>
99 <td>Private method to check various other import related topics.</td>
100 </tr>
101 <tr>
102 <td><a href="#ImportsChecker.getStandardModules">getStandardModules</a></td>
103 <td>Public method to get a list of modules of the standard library.</td>
104 </tr>
105 <tr>
106 <td><a href="#ImportsChecker.run">run</a></td>
107 <td>Public method to check the given source against miscellaneous conditions.</td>
108 </tr>
109 </table>
110 <h3>Static Methods</h3>
111
112 <table>
113 <tr><td>None</td></tr>
114 </table>
115
116 <a NAME="ImportsChecker.__init__" ID="ImportsChecker.__init__"></a>
117 <h4>ImportsChecker (Constructor)</h4>
118 <b>ImportsChecker</b>(<i>source, filename, tree, select, ignore, expected, repeat, args</i>)
119
120 <p>
121 Constructor
122 </p>
123 <dl>
124
125 <dt><i>source</i> (list of str)</dt>
126 <dd>
127 source code to be checked
128 </dd>
129 <dt><i>filename</i> (str)</dt>
130 <dd>
131 name of the source file
132 </dd>
133 <dt><i>tree</i> (ast.Module)</dt>
134 <dd>
135 AST tree of the source code
136 </dd>
137 <dt><i>select</i> (list of str)</dt>
138 <dd>
139 list of selected codes
140 </dd>
141 <dt><i>ignore</i> (list of str)</dt>
142 <dd>
143 list of codes to be ignored
144 </dd>
145 <dt><i>expected</i> (list of str)</dt>
146 <dd>
147 list of expected codes
148 </dd>
149 <dt><i>repeat</i> (bool)</dt>
150 <dd>
151 flag indicating to report each occurrence of a code
152 </dd>
153 <dt><i>args</i> (dict)</dt>
154 <dd>
155 dictionary of arguments for the various checks
156 </dd>
157 </dl>
158 <a NAME="ImportsChecker.__checkBannedImport" ID="ImportsChecker.__checkBannedImport"></a>
159 <h4>ImportsChecker.__checkBannedImport</h4>
160 <b>__checkBannedImport</b>(<i>node</i>)
161
162 <p>
163 Private method to check import of banned modules.
164 </p>
165 <dl>
166
167 <dt><i>node</i> (ast.AST)</dt>
168 <dd>
169 reference to the node to be checked
170 </dd>
171 </dl>
172 <a NAME="ImportsChecker.__checkBannedRelativeImports" ID="ImportsChecker.__checkBannedRelativeImports"></a>
173 <h4>ImportsChecker.__checkBannedRelativeImports</h4>
174 <b>__checkBannedRelativeImports</b>(<i>node</i>)
175
176 <p>
177 Private method to check if relative imports are banned.
178 </p>
179 <dl>
180
181 <dt><i>node</i> (ast.AST)</dt>
182 <dd>
183 reference to the node to be checked
184 </dd>
185 </dl>
186 <a NAME="ImportsChecker.__checkImportOrder" ID="ImportsChecker.__checkImportOrder"></a>
187 <h4>ImportsChecker.__checkImportOrder</h4>
188 <b>__checkImportOrder</b>(<i></i>)
189
190 <p>
191 Private method to check the order of import statements.
192 </p>
193 <a NAME="ImportsChecker.__checkLocalImports" ID="ImportsChecker.__checkLocalImports"></a>
194 <h4>ImportsChecker.__checkLocalImports</h4>
195 <b>__checkLocalImports</b>(<i></i>)
196
197 <p>
198 Private method to check local imports.
199 </p>
200 <a NAME="ImportsChecker.__checkUnnecessaryAlias" ID="ImportsChecker.__checkUnnecessaryAlias"></a>
201 <h4>ImportsChecker.__checkUnnecessaryAlias</h4>
202 <b>__checkUnnecessaryAlias</b>(<i>node</i>)
203
204 <p>
205 Private method to check unnecessary import aliases.
206 </p>
207 <dl>
208
209 <dt><i>node</i> (ast.AST)</dt>
210 <dd>
211 reference to the node to be checked
212 </dd>
213 </dl>
214 <a NAME="ImportsChecker.__error" ID="ImportsChecker.__error"></a>
215 <h4>ImportsChecker.__error</h4>
216 <b>__error</b>(<i>lineNumber, offset, code, *args</i>)
217
218 <p>
219 Private method to record an issue.
220 </p>
221 <dl>
222
223 <dt><i>lineNumber</i> (int)</dt>
224 <dd>
225 line number of the issue
226 </dd>
227 <dt><i>offset</i> (int)</dt>
228 <dd>
229 position within line of the issue
230 </dd>
231 <dt><i>code</i> (str)</dt>
232 <dd>
233 message code
234 </dd>
235 <dt><i>args</i> (list)</dt>
236 <dd>
237 arguments for the message
238 </dd>
239 </dl>
240 <a NAME="ImportsChecker.__findErrorInAll" ID="ImportsChecker.__findErrorInAll"></a>
241 <h4>ImportsChecker.__findErrorInAll</h4>
242 <b>__findErrorInAll</b>(<i>node</i>)
243
244 <p>
245 Private method to check the '__all__' node for errors.
246 </p>
247 <dl>
248
249 <dt><i>node</i> (ast.List or ast.Tuple)</dt>
250 <dd>
251 reference to the '__all__' node
252 </dd>
253 </dl>
254 <dl>
255 <dt>Return:</dt>
256 <dd>
257 tuple containing a reference to the node and an error code
258 </dd>
259 </dl>
260 <dl>
261 <dt>Return Type:</dt>
262 <dd>
263 rtype tuple of (ast.List | ast.Tuple, str)
264 </dd>
265 </dl>
266 <a NAME="ImportsChecker.__findNodes" ID="ImportsChecker.__findNodes"></a>
267 <h4>ImportsChecker.__findNodes</h4>
268 <b>__findNodes</b>(<i>tree</i>)
269
270 <p>
271 Private method to find all import and import from nodes of the given
272 tree.
273 </p>
274 <dl>
275
276 <dt><i>tree</i> (ast.AST)</dt>
277 <dd>
278 reference to the ast node tree to be parsed
279 </dd>
280 </dl>
281 <dl>
282 <dt>Return:</dt>
283 <dd>
284 tuple containing a list of import nodes and the '__all__' node
285 </dd>
286 </dl>
287 <dl>
288 <dt>Return Type:</dt>
289 <dd>
290 tuple of (ast.Import | ast.ImportFrom, ast.List | ast.Tuple)
291 </dd>
292 </dl>
293 <a NAME="ImportsChecker.__ignoreCode" ID="ImportsChecker.__ignoreCode"></a>
294 <h4>ImportsChecker.__ignoreCode</h4>
295 <b>__ignoreCode</b>(<i>code</i>)
296
297 <p>
298 Private method to check if the message code should be ignored.
299 </p>
300 <dl>
301
302 <dt><i>code</i> (str)</dt>
303 <dd>
304 message code to check for
305 </dd>
306 </dl>
307 <dl>
308 <dt>Return:</dt>
309 <dd>
310 flag indicating to ignore the given code
311 </dd>
312 </dl>
313 <dl>
314 <dt>Return Type:</dt>
315 <dd>
316 bool
317 </dd>
318 </dl>
319 <a NAME="ImportsChecker.__tidyImports" ID="ImportsChecker.__tidyImports"></a>
320 <h4>ImportsChecker.__tidyImports</h4>
321 <b>__tidyImports</b>(<i></i>)
322
323 <p>
324 Private method to check various other import related topics.
325 </p>
326 <a NAME="ImportsChecker.getStandardModules" ID="ImportsChecker.getStandardModules"></a>
327 <h4>ImportsChecker.getStandardModules</h4>
328 <b>getStandardModules</b>(<i></i>)
329
330 <p>
331 Public method to get a list of modules of the standard library.
332 </p>
333 <dl>
334 <dt>Return:</dt>
335 <dd>
336 set of builtin modules
337 </dd>
338 </dl>
339 <dl>
340 <dt>Return Type:</dt>
341 <dd>
342 set of str
343 </dd>
344 </dl>
345 <a NAME="ImportsChecker.run" ID="ImportsChecker.run"></a>
346 <h4>ImportsChecker.run</h4>
347 <b>run</b>(<i></i>)
348
349 <p>
350 Public method to check the given source against miscellaneous
351 conditions.
352 </p>
353 <div align="right"><a href="#top">Up</a></div>
354 <hr />
355 </body></html>

eric ide

mercurial