Documentation/Source/eric5.Plugins.CheckerPlugins.Pep8.Pep8NamingChecker.html

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

eric ide

mercurial