|
1 <!DOCTYPE html> |
|
2 <html><head> |
|
3 <title>eric5.UtilitiesPython2.Pep8NamingCheckerPy2</title> |
|
4 <meta charset="UTF-8"> |
|
5 <style> |
|
6 body { |
|
7 background: #EDECE6; |
|
8 margin: 0em 1em 10em 1em; |
|
9 color: black; |
|
10 } |
|
11 |
|
12 h1 { color: white; background: #85774A; } |
|
13 h2 { color: white; background: #85774A; } |
|
14 h3 { color: white; background: #9D936E; } |
|
15 h4 { color: white; background: #9D936E; } |
|
16 |
|
17 a { color: #BA6D36; } |
|
18 |
|
19 </style> |
|
20 </head> |
|
21 <body><a NAME="top" ID="top"></a> |
|
22 <h1>eric5.UtilitiesPython2.Pep8NamingCheckerPy2</h1> |
|
23 <p> |
|
24 Module implementing a checker for PEP-8 naming conventions for Python2. |
|
25 </p> |
|
26 <h3>Global Attributes</h3> |
|
27 <table> |
|
28 <tr><td>None</td></tr> |
|
29 </table> |
|
30 <h3>Classes</h3> |
|
31 <table> |
|
32 <tr> |
|
33 <td><a href="#Pep8NamingChecker">Pep8NamingChecker</a></td> |
|
34 <td>Class implementing a checker for PEP-8 naming conventions for Python2.</td> |
|
35 </tr> |
|
36 </table> |
|
37 <h3>Functions</h3> |
|
38 <table> |
|
39 <tr><td>None</td></tr> |
|
40 </table> |
|
41 <hr /><hr /> |
|
42 <a NAME="Pep8NamingChecker" ID="Pep8NamingChecker"></a> |
|
43 <h2>Pep8NamingChecker</h2> |
|
44 <p> |
|
45 Class implementing a checker for PEP-8 naming conventions for Python2. |
|
46 </p> |
|
47 <h3>Derived from</h3> |
|
48 object |
|
49 <h3>Class Attributes</h3> |
|
50 <table> |
|
51 <tr><td>CamelcaseRegexp</td></tr><tr><td>Codes</td></tr><tr><td>LowercaseRegex</td></tr><tr><td>MixedcaseRegexp</td></tr><tr><td>UppercaseRegexp</td></tr> |
|
52 </table> |
|
53 <h3>Class Methods</h3> |
|
54 <table> |
|
55 <tr><td>None</td></tr> |
|
56 </table> |
|
57 <h3>Methods</h3> |
|
58 <table> |
|
59 <tr> |
|
60 <td><a href="#Pep8NamingChecker.__init__">Pep8NamingChecker</a></td> |
|
61 <td>Constructor (according to pep8.py API)</td> |
|
62 </tr><tr> |
|
63 <td><a href="#Pep8NamingChecker.__checkClassName">__checkClassName</a></td> |
|
64 <td>Private class to check the given node for class name conventions (N801, N831).</td> |
|
65 </tr><tr> |
|
66 <td><a href="#Pep8NamingChecker.__checkFunctionArgumentNames">__checkFunctionArgumentNames</a></td> |
|
67 <td>Private class to check the argument names of functions (N803, N804, N805, N806, N831).</td> |
|
68 </tr><tr> |
|
69 <td><a href="#Pep8NamingChecker.__checkFuntionName">__checkFuntionName</a></td> |
|
70 <td>Private class to check the given node for function name conventions (N802, N831).</td> |
|
71 </tr><tr> |
|
72 <td><a href="#Pep8NamingChecker.__checkImportAs">__checkImportAs</a></td> |
|
73 <td>Private method to check that imports don't change the naming convention (N811, N812, N813, N814).</td> |
|
74 </tr><tr> |
|
75 <td><a href="#Pep8NamingChecker.__checkModule">__checkModule</a></td> |
|
76 <td>Private method to check module naming conventions (N807, N808).</td> |
|
77 </tr><tr> |
|
78 <td><a href="#Pep8NamingChecker.__checkVariablesInFunction">__checkVariablesInFunction</a></td> |
|
79 <td>Private method to check local variables in functions (N821, N831).</td> |
|
80 </tr><tr> |
|
81 <td><a href="#Pep8NamingChecker.__error">__error</a></td> |
|
82 <td>Private method to build the error information</td> |
|
83 </tr><tr> |
|
84 <td><a href="#Pep8NamingChecker.__findGlobalDefs">__findGlobalDefs</a></td> |
|
85 <td>Private method amend a node with global definitions information.</td> |
|
86 </tr><tr> |
|
87 <td><a href="#Pep8NamingChecker.__getArgNames">__getArgNames</a></td> |
|
88 <td>Private method to get the argument names of a function node.</td> |
|
89 </tr><tr> |
|
90 <td><a href="#Pep8NamingChecker.__isNameToBeAvoided">__isNameToBeAvoided</a></td> |
|
91 <td>Private method to check, if the given name should be avoided.</td> |
|
92 </tr><tr> |
|
93 <td><a href="#Pep8NamingChecker.__tagClassFunctions">__tagClassFunctions</a></td> |
|
94 <td>Private method to tag functions if they are methods, class methods or static methods.</td> |
|
95 </tr><tr> |
|
96 <td><a href="#Pep8NamingChecker.__visitNode">__visitNode</a></td> |
|
97 <td>Private method to inspect the given AST node.</td> |
|
98 </tr><tr> |
|
99 <td><a href="#Pep8NamingChecker.__visitTree">__visitTree</a></td> |
|
100 <td>Private method to scan the given AST tree.</td> |
|
101 </tr><tr> |
|
102 <td><a href="#Pep8NamingChecker.run">run</a></td> |
|
103 <td>Public method run by the pep8.py checker.</td> |
|
104 </tr><tr> |
|
105 <td><a href="#Pep8NamingChecker.unpackArgs">unpackArgs</a></td> |
|
106 <td>Local helper function to unpack function argument names.</td> |
|
107 </tr> |
|
108 </table> |
|
109 <h3>Static Methods</h3> |
|
110 <table> |
|
111 <tr><td>None</td></tr> |
|
112 </table> |
|
113 <a NAME="Pep8NamingChecker.__init__" ID="Pep8NamingChecker.__init__"></a> |
|
114 <h4>Pep8NamingChecker (Constructor)</h4> |
|
115 <b>Pep8NamingChecker</b>(<i>tree, filename</i>) |
|
116 <p> |
|
117 Constructor (according to pep8.py API) |
|
118 </p><dl> |
|
119 <dt><i>tree</i></dt> |
|
120 <dd> |
|
121 AST tree of the source file |
|
122 </dd><dt><i>filename</i></dt> |
|
123 <dd> |
|
124 name of the source file (string) |
|
125 </dd> |
|
126 </dl><a NAME="Pep8NamingChecker.__checkClassName" ID="Pep8NamingChecker.__checkClassName"></a> |
|
127 <h4>Pep8NamingChecker.__checkClassName</h4> |
|
128 <b>__checkClassName</b>(<i>node, parents</i>) |
|
129 <p> |
|
130 Private class to check the given node for class name |
|
131 conventions (N801, N831). |
|
132 </p><p> |
|
133 Almost without exception, class names use the CapWords convention. |
|
134 Classes for internal use have a leading underscore in addition. |
|
135 </p><dl> |
|
136 <dt><i>node</i></dt> |
|
137 <dd> |
|
138 AST note to check |
|
139 </dd> |
|
140 </dl><dl> |
|
141 <dt>Returns:</dt> |
|
142 <dd> |
|
143 tuple giving line number, offset within line and error code |
|
144 (integer, integer, string) |
|
145 </dd> |
|
146 </dl><a NAME="Pep8NamingChecker.__checkFunctionArgumentNames" ID="Pep8NamingChecker.__checkFunctionArgumentNames"></a> |
|
147 <h4>Pep8NamingChecker.__checkFunctionArgumentNames</h4> |
|
148 <b>__checkFunctionArgumentNames</b>(<i>node, parents</i>) |
|
149 <p> |
|
150 Private class to check the argument names of functions |
|
151 (N803, N804, N805, N806, N831). |
|
152 </p><p> |
|
153 The argument names of a function should be lowercase, with words |
|
154 separated by underscores. A class method should have 'cls' as the |
|
155 first argument. A method should have 'self' as the first argument. |
|
156 </p><dl> |
|
157 <dt><i>node</i></dt> |
|
158 <dd> |
|
159 AST note to check |
|
160 </dd> |
|
161 </dl><dl> |
|
162 <dt>Returns:</dt> |
|
163 <dd> |
|
164 tuple giving line number, offset within line and error code |
|
165 (integer, integer, string) |
|
166 </dd> |
|
167 </dl><a NAME="Pep8NamingChecker.__checkFuntionName" ID="Pep8NamingChecker.__checkFuntionName"></a> |
|
168 <h4>Pep8NamingChecker.__checkFuntionName</h4> |
|
169 <b>__checkFuntionName</b>(<i>node, parents</i>) |
|
170 <p> |
|
171 Private class to check the given node for function name |
|
172 conventions (N802, N831). |
|
173 </p><p> |
|
174 Function names should be lowercase, with words separated by underscores |
|
175 as necessary to improve readability. Functions <b>not</b> being |
|
176 methods '__' in front and back are not allowed. Mixed case is allowed |
|
177 only in contexts where that's already the prevailing style |
|
178 (e.g. threading.py), to retain backwards compatibility. |
|
179 </p><dl> |
|
180 <dt><i>node</i></dt> |
|
181 <dd> |
|
182 AST note to check |
|
183 </dd> |
|
184 </dl><dl> |
|
185 <dt>Returns:</dt> |
|
186 <dd> |
|
187 tuple giving line number, offset within line and error code |
|
188 (integer, integer, string) |
|
189 </dd> |
|
190 </dl><a NAME="Pep8NamingChecker.__checkImportAs" ID="Pep8NamingChecker.__checkImportAs"></a> |
|
191 <h4>Pep8NamingChecker.__checkImportAs</h4> |
|
192 <b>__checkImportAs</b>(<i>node, parents</i>) |
|
193 <p> |
|
194 Private method to check that imports don't change the |
|
195 naming convention (N811, N812, N813, N814). |
|
196 </p><dl> |
|
197 <dt><i>node</i></dt> |
|
198 <dd> |
|
199 AST note to check |
|
200 </dd> |
|
201 </dl><dl> |
|
202 <dt>Returns:</dt> |
|
203 <dd> |
|
204 tuple giving line number, offset within line and error code |
|
205 (integer, integer, string) |
|
206 </dd> |
|
207 </dl><a NAME="Pep8NamingChecker.__checkModule" ID="Pep8NamingChecker.__checkModule"></a> |
|
208 <h4>Pep8NamingChecker.__checkModule</h4> |
|
209 <b>__checkModule</b>(<i>node, parents</i>) |
|
210 <p> |
|
211 Private method to check module naming conventions (N807, N808). |
|
212 </p><p> |
|
213 Module and package names should be lowercase. |
|
214 </p><dl> |
|
215 <dt><i>node</i></dt> |
|
216 <dd> |
|
217 AST note to check |
|
218 </dd> |
|
219 </dl><dl> |
|
220 <dt>Returns:</dt> |
|
221 <dd> |
|
222 tuple giving line number, offset within line and error code |
|
223 (integer, integer, string) |
|
224 </dd> |
|
225 </dl><a NAME="Pep8NamingChecker.__checkVariablesInFunction" ID="Pep8NamingChecker.__checkVariablesInFunction"></a> |
|
226 <h4>Pep8NamingChecker.__checkVariablesInFunction</h4> |
|
227 <b>__checkVariablesInFunction</b>(<i>node, parents</i>) |
|
228 <p> |
|
229 Private method to check local variables in functions (N821, N831). |
|
230 </p><p> |
|
231 Local variables in functions should be lowercase. |
|
232 </p><dl> |
|
233 <dt><i>node</i></dt> |
|
234 <dd> |
|
235 AST note to check |
|
236 </dd> |
|
237 </dl><dl> |
|
238 <dt>Returns:</dt> |
|
239 <dd> |
|
240 tuple giving line number, offset within line and error code |
|
241 (integer, integer, string) |
|
242 </dd> |
|
243 </dl><a NAME="Pep8NamingChecker.__error" ID="Pep8NamingChecker.__error"></a> |
|
244 <h4>Pep8NamingChecker.__error</h4> |
|
245 <b>__error</b>(<i>node, code</i>) |
|
246 <p> |
|
247 Private method to build the error information |
|
248 </p><dl> |
|
249 <dt><i>node</i></dt> |
|
250 <dd> |
|
251 AST node to report an error for |
|
252 </dd><dt><i>code</i></dt> |
|
253 <dd> |
|
254 error code to report (string) |
|
255 </dd> |
|
256 </dl><dl> |
|
257 <dt>Returns:</dt> |
|
258 <dd> |
|
259 tuple giving line number, offset within line and error code |
|
260 (integer, integer, string) |
|
261 </dd> |
|
262 </dl><a NAME="Pep8NamingChecker.__findGlobalDefs" ID="Pep8NamingChecker.__findGlobalDefs"></a> |
|
263 <h4>Pep8NamingChecker.__findGlobalDefs</h4> |
|
264 <b>__findGlobalDefs</b>(<i>functionNode</i>) |
|
265 <p> |
|
266 Private method amend a node with global definitions information. |
|
267 </p><dl> |
|
268 <dt><i>functionNode</i></dt> |
|
269 <dd> |
|
270 AST tree node to amend |
|
271 </dd> |
|
272 </dl><a NAME="Pep8NamingChecker.__getArgNames" ID="Pep8NamingChecker.__getArgNames"></a> |
|
273 <h4>Pep8NamingChecker.__getArgNames</h4> |
|
274 <b>__getArgNames</b>(<i>node</i>) |
|
275 <p> |
|
276 Private method to get the argument names of a function node. |
|
277 </p><dl> |
|
278 <dt><i>node</i></dt> |
|
279 <dd> |
|
280 AST node to extract arguments names from |
|
281 </dd> |
|
282 </dl><dl> |
|
283 <dt>Returns:</dt> |
|
284 <dd> |
|
285 list of argument names (list of string) |
|
286 </dd> |
|
287 </dl><a NAME="Pep8NamingChecker.__isNameToBeAvoided" ID="Pep8NamingChecker.__isNameToBeAvoided"></a> |
|
288 <h4>Pep8NamingChecker.__isNameToBeAvoided</h4> |
|
289 <b>__isNameToBeAvoided</b>(<i>name</i>) |
|
290 <p> |
|
291 Private method to check, if the given name should be avoided. |
|
292 </p><dl> |
|
293 <dt><i>name</i></dt> |
|
294 <dd> |
|
295 name to be checked (string) |
|
296 </dd> |
|
297 </dl><dl> |
|
298 <dt>Returns:</dt> |
|
299 <dd> |
|
300 flag indicating to avoid it (boolen) |
|
301 </dd> |
|
302 </dl><a NAME="Pep8NamingChecker.__tagClassFunctions" ID="Pep8NamingChecker.__tagClassFunctions"></a> |
|
303 <h4>Pep8NamingChecker.__tagClassFunctions</h4> |
|
304 <b>__tagClassFunctions</b>(<i>classNode</i>) |
|
305 <p> |
|
306 Private method to tag functions if they are methods, class methods or |
|
307 static methods. |
|
308 </p><dl> |
|
309 <dt><i>classNode</i></dt> |
|
310 <dd> |
|
311 AST tree node to tag |
|
312 </dd> |
|
313 </dl><a NAME="Pep8NamingChecker.__visitNode" ID="Pep8NamingChecker.__visitNode"></a> |
|
314 <h4>Pep8NamingChecker.__visitNode</h4> |
|
315 <b>__visitNode</b>(<i>node</i>) |
|
316 <p> |
|
317 Private method to inspect the given AST node. |
|
318 </p><dl> |
|
319 <dt><i>node</i></dt> |
|
320 <dd> |
|
321 AST tree node to inspect |
|
322 </dd> |
|
323 </dl><dl> |
|
324 <dt>Returns:</dt> |
|
325 <dd> |
|
326 tuple giving line number, offset within line, code and |
|
327 checker function |
|
328 </dd> |
|
329 </dl><a NAME="Pep8NamingChecker.__visitTree" ID="Pep8NamingChecker.__visitTree"></a> |
|
330 <h4>Pep8NamingChecker.__visitTree</h4> |
|
331 <b>__visitTree</b>(<i>node</i>) |
|
332 <p> |
|
333 Private method to scan the given AST tree. |
|
334 </p><dl> |
|
335 <dt><i>node</i></dt> |
|
336 <dd> |
|
337 AST tree node to scan |
|
338 </dd> |
|
339 </dl><dl> |
|
340 <dt>Returns:</dt> |
|
341 <dd> |
|
342 tuple giving line number, offset within line, code and |
|
343 checker function |
|
344 </dd> |
|
345 </dl><a NAME="Pep8NamingChecker.run" ID="Pep8NamingChecker.run"></a> |
|
346 <h4>Pep8NamingChecker.run</h4> |
|
347 <b>run</b>(<i></i>) |
|
348 <p> |
|
349 Public method run by the pep8.py checker. |
|
350 </p><dl> |
|
351 <dt>Returns:</dt> |
|
352 <dd> |
|
353 tuple giving line number, offset within line, code and |
|
354 checker function |
|
355 </dd> |
|
356 </dl><a NAME="Pep8NamingChecker.unpackArgs" ID="Pep8NamingChecker.unpackArgs"></a> |
|
357 <h4>Pep8NamingChecker.unpackArgs</h4> |
|
358 <b>unpackArgs</b>(<i></i>) |
|
359 <p> |
|
360 Local helper function to unpack function argument names. |
|
361 </p><dl> |
|
362 <dt><i>args</i></dt> |
|
363 <dd> |
|
364 list of AST node arguments |
|
365 </dd> |
|
366 </dl><dl> |
|
367 <dt>Returns:</dt> |
|
368 <dd> |
|
369 list of argument names (list of string) |
|
370 </dd> |
|
371 </dl> |
|
372 <div align="right"><a href="#top">Up</a></div> |
|
373 <hr /> |
|
374 </body></html> |