|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric7.Plugins.CheckerPlugins.CodeStyleChecker.PathLib.PathlibChecker</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.PathLib.PathlibChecker</h1> |
|
10 |
|
11 <p> |
|
12 Module implementing the checker for functions that can be replaced by use of |
|
13 the pathlib module. |
|
14 </p> |
|
15 <h3>Global Attributes</h3> |
|
16 |
|
17 <table> |
|
18 <tr><td>None</td></tr> |
|
19 </table> |
|
20 <h3>Classes</h3> |
|
21 |
|
22 <table> |
|
23 |
|
24 <tr> |
|
25 <td><a href="#NameResolver">NameResolver</a></td> |
|
26 <td>Class to resolve a Name or Attribute node.</td> |
|
27 </tr> |
|
28 <tr> |
|
29 <td><a href="#PathlibChecker">PathlibChecker</a></td> |
|
30 <td>Class implementing a checker for functions that can be replaced by use of the pathlib module.</td> |
|
31 </tr> |
|
32 <tr> |
|
33 <td><a href="#PathlibVisitor">PathlibVisitor</a></td> |
|
34 <td>Class to traverse the AST node tree and check for potential issues.</td> |
|
35 </tr> |
|
36 </table> |
|
37 <h3>Functions</h3> |
|
38 |
|
39 <table> |
|
40 <tr><td>None</td></tr> |
|
41 </table> |
|
42 <hr /> |
|
43 <hr /> |
|
44 <a NAME="NameResolver" ID="NameResolver"></a> |
|
45 <h2>NameResolver</h2> |
|
46 |
|
47 <p> |
|
48 Class to resolve a Name or Attribute node. |
|
49 </p> |
|
50 <h3>Derived from</h3> |
|
51 ast.NodeVisitor |
|
52 <h3>Class Attributes</h3> |
|
53 |
|
54 <table> |
|
55 <tr><td>None</td></tr> |
|
56 </table> |
|
57 <h3>Class Methods</h3> |
|
58 |
|
59 <table> |
|
60 <tr><td>None</td></tr> |
|
61 </table> |
|
62 <h3>Methods</h3> |
|
63 |
|
64 <table> |
|
65 |
|
66 <tr> |
|
67 <td><a href="#NameResolver.__init__">NameResolver</a></td> |
|
68 <td>Constructor</td> |
|
69 </tr> |
|
70 <tr> |
|
71 <td><a href="#NameResolver.name">name</a></td> |
|
72 <td>Public method to resolve the name.</td> |
|
73 </tr> |
|
74 <tr> |
|
75 <td><a href="#NameResolver.visit_Attribute">visit_Attribute</a></td> |
|
76 <td>Public method to handle the Attribute AST node.</td> |
|
77 </tr> |
|
78 <tr> |
|
79 <td><a href="#NameResolver.visit_Name">visit_Name</a></td> |
|
80 <td>Public method to handle the Name AST node.</td> |
|
81 </tr> |
|
82 </table> |
|
83 <h3>Static Methods</h3> |
|
84 |
|
85 <table> |
|
86 <tr><td>None</td></tr> |
|
87 </table> |
|
88 |
|
89 <a NAME="NameResolver.__init__" ID="NameResolver.__init__"></a> |
|
90 <h4>NameResolver (Constructor)</h4> |
|
91 <b>NameResolver</b>(<i>importAlias</i>) |
|
92 |
|
93 <p> |
|
94 Constructor |
|
95 </p> |
|
96 <dl> |
|
97 |
|
98 <dt><i>importAlias</i> (dict)</dt> |
|
99 <dd> |
|
100 reference to the import aliases dictionary |
|
101 </dd> |
|
102 </dl> |
|
103 <a NAME="NameResolver.name" ID="NameResolver.name"></a> |
|
104 <h4>NameResolver.name</h4> |
|
105 <b>name</b>(<i></i>) |
|
106 |
|
107 <p> |
|
108 Public method to resolve the name. |
|
109 </p> |
|
110 <dl> |
|
111 <dt>Return:</dt> |
|
112 <dd> |
|
113 resolved name |
|
114 </dd> |
|
115 </dl> |
|
116 <dl> |
|
117 <dt>Return Type:</dt> |
|
118 <dd> |
|
119 str |
|
120 </dd> |
|
121 </dl> |
|
122 <a NAME="NameResolver.visit_Attribute" ID="NameResolver.visit_Attribute"></a> |
|
123 <h4>NameResolver.visit_Attribute</h4> |
|
124 <b>visit_Attribute</b>(<i>node</i>) |
|
125 |
|
126 <p> |
|
127 Public method to handle the Attribute AST node. |
|
128 </p> |
|
129 <dl> |
|
130 |
|
131 <dt><i>node</i> (ast.Attribute)</dt> |
|
132 <dd> |
|
133 reference to the Attribute AST node |
|
134 </dd> |
|
135 </dl> |
|
136 <a NAME="NameResolver.visit_Name" ID="NameResolver.visit_Name"></a> |
|
137 <h4>NameResolver.visit_Name</h4> |
|
138 <b>visit_Name</b>(<i>node</i>) |
|
139 |
|
140 <p> |
|
141 Public method to handle the Name AST node. |
|
142 </p> |
|
143 <dl> |
|
144 |
|
145 <dt><i>node</i> (ast.Name)</dt> |
|
146 <dd> |
|
147 reference to the Name AST node |
|
148 </dd> |
|
149 </dl> |
|
150 <div align="right"><a href="#top">Up</a></div> |
|
151 <hr /> |
|
152 <hr /> |
|
153 <a NAME="PathlibChecker" ID="PathlibChecker"></a> |
|
154 <h2>PathlibChecker</h2> |
|
155 |
|
156 <p> |
|
157 Class implementing a checker for functions that can be replaced by use of |
|
158 the pathlib module. |
|
159 </p> |
|
160 <h3>Derived from</h3> |
|
161 None |
|
162 <h3>Class Attributes</h3> |
|
163 |
|
164 <table> |
|
165 <tr><td>Codes</td></tr><tr><td>Function2Code</td></tr> |
|
166 </table> |
|
167 <h3>Class Methods</h3> |
|
168 |
|
169 <table> |
|
170 <tr><td>None</td></tr> |
|
171 </table> |
|
172 <h3>Methods</h3> |
|
173 |
|
174 <table> |
|
175 |
|
176 <tr> |
|
177 <td><a href="#PathlibChecker.__init__">PathlibChecker</a></td> |
|
178 <td>Constructor</td> |
|
179 </tr> |
|
180 <tr> |
|
181 <td><a href="#PathlibChecker.__checkForReplacement">__checkForReplacement</a></td> |
|
182 <td>Private method to check the given node for the need for a replacement.</td> |
|
183 </tr> |
|
184 <tr> |
|
185 <td><a href="#PathlibChecker.__error">__error</a></td> |
|
186 <td>Private method to record an issue.</td> |
|
187 </tr> |
|
188 <tr> |
|
189 <td><a href="#PathlibChecker.__ignoreCode">__ignoreCode</a></td> |
|
190 <td>Private method to check if the message code should be ignored.</td> |
|
191 </tr> |
|
192 <tr> |
|
193 <td><a href="#PathlibChecker.run">run</a></td> |
|
194 <td>Public method to check the given source against functions to be replaced by 'pathlib' equivalents.</td> |
|
195 </tr> |
|
196 </table> |
|
197 <h3>Static Methods</h3> |
|
198 |
|
199 <table> |
|
200 <tr><td>None</td></tr> |
|
201 </table> |
|
202 |
|
203 <a NAME="PathlibChecker.__init__" ID="PathlibChecker.__init__"></a> |
|
204 <h4>PathlibChecker (Constructor)</h4> |
|
205 <b>PathlibChecker</b>(<i>source, filename, tree, selected, ignored, expected, repeat</i>) |
|
206 |
|
207 <p> |
|
208 Constructor |
|
209 </p> |
|
210 <dl> |
|
211 |
|
212 <dt><i>source</i> (list of str)</dt> |
|
213 <dd> |
|
214 source code to be checked |
|
215 </dd> |
|
216 <dt><i>filename</i> (str)</dt> |
|
217 <dd> |
|
218 name of the source file |
|
219 </dd> |
|
220 <dt><i>tree</i> (ast.Module)</dt> |
|
221 <dd> |
|
222 AST tree of the source code |
|
223 </dd> |
|
224 <dt><i>selected</i> (list of str)</dt> |
|
225 <dd> |
|
226 list of selected codes |
|
227 </dd> |
|
228 <dt><i>ignored</i> (list of str)</dt> |
|
229 <dd> |
|
230 list of codes to be ignored |
|
231 </dd> |
|
232 <dt><i>expected</i> (list of str)</dt> |
|
233 <dd> |
|
234 list of expected codes |
|
235 </dd> |
|
236 <dt><i>repeat</i> (bool)</dt> |
|
237 <dd> |
|
238 flag indicating to report each occurrence of a code |
|
239 </dd> |
|
240 </dl> |
|
241 <a NAME="PathlibChecker.__checkForReplacement" ID="PathlibChecker.__checkForReplacement"></a> |
|
242 <h4>PathlibChecker.__checkForReplacement</h4> |
|
243 <b>__checkForReplacement</b>(<i>node, name</i>) |
|
244 |
|
245 <p> |
|
246 Private method to check the given node for the need for a |
|
247 replacement. |
|
248 </p> |
|
249 <dl> |
|
250 |
|
251 <dt><i>node</i> (ast.AST)</dt> |
|
252 <dd> |
|
253 reference to the AST node to check |
|
254 </dd> |
|
255 <dt><i>name</i> (str)</dt> |
|
256 <dd> |
|
257 resolved name of the node |
|
258 </dd> |
|
259 </dl> |
|
260 <a NAME="PathlibChecker.__error" ID="PathlibChecker.__error"></a> |
|
261 <h4>PathlibChecker.__error</h4> |
|
262 <b>__error</b>(<i>lineNumber, offset, code, *args</i>) |
|
263 |
|
264 <p> |
|
265 Private method to record an issue. |
|
266 </p> |
|
267 <dl> |
|
268 |
|
269 <dt><i>lineNumber</i> (int)</dt> |
|
270 <dd> |
|
271 line number of the issue |
|
272 </dd> |
|
273 <dt><i>offset</i> (int)</dt> |
|
274 <dd> |
|
275 position within line of the issue |
|
276 </dd> |
|
277 <dt><i>code</i> (str)</dt> |
|
278 <dd> |
|
279 message code |
|
280 </dd> |
|
281 <dt><i>args</i> (list)</dt> |
|
282 <dd> |
|
283 arguments for the message |
|
284 </dd> |
|
285 </dl> |
|
286 <a NAME="PathlibChecker.__ignoreCode" ID="PathlibChecker.__ignoreCode"></a> |
|
287 <h4>PathlibChecker.__ignoreCode</h4> |
|
288 <b>__ignoreCode</b>(<i>code</i>) |
|
289 |
|
290 <p> |
|
291 Private method to check if the message code should be ignored. |
|
292 </p> |
|
293 <dl> |
|
294 |
|
295 <dt><i>code</i> (str)</dt> |
|
296 <dd> |
|
297 message code to check for |
|
298 </dd> |
|
299 </dl> |
|
300 <dl> |
|
301 <dt>Return:</dt> |
|
302 <dd> |
|
303 flag indicating to ignore the given code |
|
304 </dd> |
|
305 </dl> |
|
306 <dl> |
|
307 <dt>Return Type:</dt> |
|
308 <dd> |
|
309 bool |
|
310 </dd> |
|
311 </dl> |
|
312 <a NAME="PathlibChecker.run" ID="PathlibChecker.run"></a> |
|
313 <h4>PathlibChecker.run</h4> |
|
314 <b>run</b>(<i></i>) |
|
315 |
|
316 <p> |
|
317 Public method to check the given source against functions |
|
318 to be replaced by 'pathlib' equivalents. |
|
319 </p> |
|
320 <div align="right"><a href="#top">Up</a></div> |
|
321 <hr /> |
|
322 <hr /> |
|
323 <a NAME="PathlibVisitor" ID="PathlibVisitor"></a> |
|
324 <h2>PathlibVisitor</h2> |
|
325 |
|
326 <p> |
|
327 Class to traverse the AST node tree and check for potential issues. |
|
328 </p> |
|
329 <h3>Derived from</h3> |
|
330 ast.NodeVisitor |
|
331 <h3>Class Attributes</h3> |
|
332 |
|
333 <table> |
|
334 <tr><td>None</td></tr> |
|
335 </table> |
|
336 <h3>Class Methods</h3> |
|
337 |
|
338 <table> |
|
339 <tr><td>None</td></tr> |
|
340 </table> |
|
341 <h3>Methods</h3> |
|
342 |
|
343 <table> |
|
344 |
|
345 <tr> |
|
346 <td><a href="#PathlibVisitor.__init__">PathlibVisitor</a></td> |
|
347 <td>Constructor</td> |
|
348 </tr> |
|
349 <tr> |
|
350 <td><a href="#PathlibVisitor.visit_Call">visit_Call</a></td> |
|
351 <td>Public method to handle the Call AST node.</td> |
|
352 </tr> |
|
353 <tr> |
|
354 <td><a href="#PathlibVisitor.visit_Import">visit_Import</a></td> |
|
355 <td>Public method to handle the Import AST node.</td> |
|
356 </tr> |
|
357 <tr> |
|
358 <td><a href="#PathlibVisitor.visit_ImportFrom">visit_ImportFrom</a></td> |
|
359 <td>Public method handle the ImportFrom AST node.</td> |
|
360 </tr> |
|
361 </table> |
|
362 <h3>Static Methods</h3> |
|
363 |
|
364 <table> |
|
365 <tr><td>None</td></tr> |
|
366 </table> |
|
367 |
|
368 <a NAME="PathlibVisitor.__init__" ID="PathlibVisitor.__init__"></a> |
|
369 <h4>PathlibVisitor (Constructor)</h4> |
|
370 <b>PathlibVisitor</b>(<i>checkCallback</i>) |
|
371 |
|
372 <p> |
|
373 Constructor |
|
374 </p> |
|
375 <dl> |
|
376 |
|
377 <dt><i>checkCallback</i> (func)</dt> |
|
378 <dd> |
|
379 callback function taking a reference to the |
|
380 AST node and the resolved name |
|
381 </dd> |
|
382 </dl> |
|
383 <a NAME="PathlibVisitor.visit_Call" ID="PathlibVisitor.visit_Call"></a> |
|
384 <h4>PathlibVisitor.visit_Call</h4> |
|
385 <b>visit_Call</b>(<i>node</i>) |
|
386 |
|
387 <p> |
|
388 Public method to handle the Call AST node. |
|
389 </p> |
|
390 <dl> |
|
391 |
|
392 <dt><i>node</i> (ast.Call)</dt> |
|
393 <dd> |
|
394 reference to the Call AST node |
|
395 </dd> |
|
396 </dl> |
|
397 <a NAME="PathlibVisitor.visit_Import" ID="PathlibVisitor.visit_Import"></a> |
|
398 <h4>PathlibVisitor.visit_Import</h4> |
|
399 <b>visit_Import</b>(<i>node</i>) |
|
400 |
|
401 <p> |
|
402 Public method to handle the Import AST node. |
|
403 </p> |
|
404 <dl> |
|
405 |
|
406 <dt><i>node</i> (ast.Import)</dt> |
|
407 <dd> |
|
408 reference to the Import AST node |
|
409 </dd> |
|
410 </dl> |
|
411 <a NAME="PathlibVisitor.visit_ImportFrom" ID="PathlibVisitor.visit_ImportFrom"></a> |
|
412 <h4>PathlibVisitor.visit_ImportFrom</h4> |
|
413 <b>visit_ImportFrom</b>(<i>node</i>) |
|
414 |
|
415 <p> |
|
416 Public method handle the ImportFrom AST node. |
|
417 </p> |
|
418 <dl> |
|
419 |
|
420 <dt><i>node</i> (ast.ImportFrom)</dt> |
|
421 <dd> |
|
422 reference to the ImportFrom AST node |
|
423 </dd> |
|
424 </dl> |
|
425 <div align="right"><a href="#top">Up</a></div> |
|
426 <hr /> |
|
427 </body></html> |