|
1 <?xml version="1.0" encoding="utf-8"?> |
|
2 <!DOCTYPE html PUBLIC '-//W3C//DTD XHTML 1.0 Strict//EN' |
|
3 'http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd'> |
|
4 <html><head> |
|
5 <title>eric5.UtilitiesPython2.pep8</title> |
|
6 <style> |
|
7 body { |
|
8 background: #EDECE6; |
|
9 margin: 0em 1em 10em 1em; |
|
10 color: black; |
|
11 } |
|
12 |
|
13 h1 { color: white; background: #85774A; } |
|
14 h2 { color: white; background: #85774A; } |
|
15 h3 { color: white; background: #9D936E; } |
|
16 h4 { color: white; background: #9D936E; } |
|
17 |
|
18 a { color: #BA6D36; } |
|
19 |
|
20 </style> |
|
21 </head> |
|
22 <body><a NAME="top" ID="top"></a> |
|
23 <h1>eric5.UtilitiesPython2.pep8</h1> |
|
24 |
|
25 <h3>Global Attributes</h3> |
|
26 <table> |
|
27 <tr><td>BENCHMARK_KEYS</td></tr><tr><td>BINARY_OPERATORS</td></tr><tr><td>DEFAULT_EXCLUDE</td></tr><tr><td>DEFAULT_IGNORE</td></tr><tr><td>DOCSTRING_REGEX</td></tr><tr><td>E225NOT_KEYWORDS</td></tr><tr><td>ERRORCODE_REGEX</td></tr><tr><td>EXTRANEOUS_WHITESPACE_REGEX</td></tr><tr><td>INDENT_REGEX</td></tr><tr><td>MAX_LINE_LENGTH</td></tr><tr><td>OPERATORS</td></tr><tr><td>RAISE_COMMA_REGEX</td></tr><tr><td>SELFTEST_REGEX</td></tr><tr><td>SKIP_TOKENS</td></tr><tr><td>UNARY_OPERATORS</td></tr><tr><td>WHITESPACE</td></tr><tr><td>WHITESPACE_AROUND_NAMED_PARAMETER_REGEX</td></tr><tr><td>WHITESPACE_AROUND_OPERATOR_REGEX</td></tr><tr><td>__version__</td></tr><tr><td>args</td></tr><tr><td>options</td></tr> |
|
28 </table> |
|
29 <h3>Classes</h3> |
|
30 <table> |
|
31 <tr> |
|
32 <td><a href="#Checker">Checker</a></td> |
|
33 <td>Load a Python source file, tokenize it, check coding style.</td> |
|
34 </tr> |
|
35 </table> |
|
36 <h3>Functions</h3> |
|
37 <table> |
|
38 <tr> |
|
39 <td><a href="#_main">_main</a></td> |
|
40 <td>Parse options and run checks on Python source.</td> |
|
41 </tr><tr> |
|
42 <td><a href="#blank_lines">blank_lines</a></td> |
|
43 <td></td> |
|
44 </tr><tr> |
|
45 <td><a href="#compound_statements">compound_statements</a></td> |
|
46 <td></td> |
|
47 </tr><tr> |
|
48 <td><a href="#excluded">excluded</a></td> |
|
49 <td>Check if options.exclude contains a pattern that matches filename.</td> |
|
50 </tr><tr> |
|
51 <td><a href="#expand_indent">expand_indent</a></td> |
|
52 <td>Return the amount of indentation.</td> |
|
53 </tr><tr> |
|
54 <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td> |
|
55 <td>Avoid extraneous whitespace in the following situations:</td> |
|
56 </tr><tr> |
|
57 <td><a href="#filename_match">filename_match</a></td> |
|
58 <td>Check if options.filename contains a pattern that matches filename.</td> |
|
59 </tr><tr> |
|
60 <td><a href="#find_checks">find_checks</a></td> |
|
61 <td>Find all globally visible functions where the first argument name starts with argument_name.</td> |
|
62 </tr><tr> |
|
63 <td><a href="#get_count">get_count</a></td> |
|
64 <td>Return the total count of errors and warnings.</td> |
|
65 </tr><tr> |
|
66 <td><a href="#get_error_statistics">get_error_statistics</a></td> |
|
67 <td>Get error statistics.</td> |
|
68 </tr><tr> |
|
69 <td><a href="#get_statistics">get_statistics</a></td> |
|
70 <td>Get statistics for message codes that start with the prefix.</td> |
|
71 </tr><tr> |
|
72 <td><a href="#get_warning_statistics">get_warning_statistics</a></td> |
|
73 <td>Get warning statistics.</td> |
|
74 </tr><tr> |
|
75 <td><a href="#ignore_code">ignore_code</a></td> |
|
76 <td>Check if options.ignore contains a prefix of the error code.</td> |
|
77 </tr><tr> |
|
78 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td> |
|
79 <td></td> |
|
80 </tr><tr> |
|
81 <td><a href="#indentation">indentation</a></td> |
|
82 <td></td> |
|
83 </tr><tr> |
|
84 <td><a href="#input_dir">input_dir</a></td> |
|
85 <td>Check all Python source files in this directory and all subdirectories.</td> |
|
86 </tr><tr> |
|
87 <td><a href="#input_file">input_file</a></td> |
|
88 <td>Run all checks on a Python source file.</td> |
|
89 </tr><tr> |
|
90 <td><a href="#maximum_line_length">maximum_line_length</a></td> |
|
91 <td>Limit all lines to a maximum of 79 characters.</td> |
|
92 </tr><tr> |
|
93 <td><a href="#message">message</a></td> |
|
94 <td>Print a message.</td> |
|
95 </tr><tr> |
|
96 <td><a href="#missing_newline">missing_newline</a></td> |
|
97 <td>JCR: The last line should have a newline.</td> |
|
98 </tr><tr> |
|
99 <td><a href="#missing_whitespace">missing_whitespace</a></td> |
|
100 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td> |
|
101 </tr><tr> |
|
102 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td> |
|
103 <td></td> |
|
104 </tr><tr> |
|
105 <td><a href="#mute_string">mute_string</a></td> |
|
106 <td>Replace contents with 'xxx' to prevent syntax matching.</td> |
|
107 </tr><tr> |
|
108 <td><a href="#print_benchmark">print_benchmark</a></td> |
|
109 <td>Print benchmark numbers.</td> |
|
110 </tr><tr> |
|
111 <td><a href="#print_statistics">print_statistics</a></td> |
|
112 <td>Print overall statistics (number of errors and warnings).</td> |
|
113 </tr><tr> |
|
114 <td><a href="#process_options">process_options</a></td> |
|
115 <td>Process options passed either via arglist or via command line args.</td> |
|
116 </tr><tr> |
|
117 <td><a href="#python_3000_backticks">python_3000_backticks</a></td> |
|
118 <td>Backticks are removed in Python 3000.</td> |
|
119 </tr><tr> |
|
120 <td><a href="#python_3000_has_key">python_3000_has_key</a></td> |
|
121 <td>The {}.has_key() method will be removed in the future version of Python.</td> |
|
122 </tr><tr> |
|
123 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td> |
|
124 <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td> |
|
125 </tr><tr> |
|
126 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td> |
|
127 <td>When raising an exception, use "raise ValueError('message')" instead of the older form "raise ValueError, 'message'".</td> |
|
128 </tr><tr> |
|
129 <td><a href="#readlines">readlines</a></td> |
|
130 <td></td> |
|
131 </tr><tr> |
|
132 <td><a href="#readlines_1">readlines</a></td> |
|
133 <td></td> |
|
134 </tr><tr> |
|
135 <td><a href="#reset_counters">reset_counters</a></td> |
|
136 <td></td> |
|
137 </tr><tr> |
|
138 <td><a href="#run_tests">run_tests</a></td> |
|
139 <td>Run all the tests from a file.</td> |
|
140 </tr><tr> |
|
141 <td><a href="#selftest">selftest</a></td> |
|
142 <td>Test all check functions with test cases in docstrings.</td> |
|
143 </tr><tr> |
|
144 <td><a href="#tabs_obsolete">tabs_obsolete</a></td> |
|
145 <td></td> |
|
146 </tr><tr> |
|
147 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td> |
|
148 <td></td> |
|
149 </tr><tr> |
|
150 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td> |
|
151 <td></td> |
|
152 </tr><tr> |
|
153 <td><a href="#trailing_whitespace">trailing_whitespace</a></td> |
|
154 <td></td> |
|
155 </tr><tr> |
|
156 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td> |
|
157 <td>Avoid extraneous whitespace in the following situations:</td> |
|
158 </tr><tr> |
|
159 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td> |
|
160 <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td> |
|
161 </tr><tr> |
|
162 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td> |
|
163 <td>Avoid extraneous whitespace in the following situations:</td> |
|
164 </tr><tr> |
|
165 <td><a href="#whitespace_before_inline_comment">whitespace_before_inline_comment</a></td> |
|
166 <td>Separate inline comments by at least two spaces.</td> |
|
167 </tr><tr> |
|
168 <td><a href="#whitespace_before_parameters">whitespace_before_parameters</a></td> |
|
169 <td>Avoid extraneous whitespace in the following situations:</td> |
|
170 </tr> |
|
171 </table> |
|
172 <hr /><hr /> |
|
173 <a NAME="Checker" ID="Checker"></a> |
|
174 <h2>Checker</h2> |
|
175 <p> |
|
176 Load a Python source file, tokenize it, check coding style. |
|
177 </p> |
|
178 <h3>Derived from</h3> |
|
179 object |
|
180 <h3>Class Attributes</h3> |
|
181 <table> |
|
182 <tr><td>None</td></tr> |
|
183 </table> |
|
184 <h3>Methods</h3> |
|
185 <table> |
|
186 <tr> |
|
187 <td><a href="#Checker.__init__">Checker</a></td> |
|
188 <td></td> |
|
189 </tr><tr> |
|
190 <td><a href="#Checker.build_tokens_line">build_tokens_line</a></td> |
|
191 <td>Build a logical line from tokens.</td> |
|
192 </tr><tr> |
|
193 <td><a href="#Checker.check_all">check_all</a></td> |
|
194 <td>Run all checks on the input file.</td> |
|
195 </tr><tr> |
|
196 <td><a href="#Checker.check_logical">check_logical</a></td> |
|
197 <td>Build a line from tokens and run all logical checks on it.</td> |
|
198 </tr><tr> |
|
199 <td><a href="#Checker.check_physical">check_physical</a></td> |
|
200 <td>Run all physical checks on a raw input line.</td> |
|
201 </tr><tr> |
|
202 <td><a href="#Checker.readline">readline</a></td> |
|
203 <td>Get the next line from the input buffer.</td> |
|
204 </tr><tr> |
|
205 <td><a href="#Checker.readline_check_physical">readline_check_physical</a></td> |
|
206 <td>Check and return the next physical line.</td> |
|
207 </tr><tr> |
|
208 <td><a href="#Checker.report_error">report_error</a></td> |
|
209 <td>Report an error, according to options.</td> |
|
210 </tr><tr> |
|
211 <td><a href="#Checker.run_check">run_check</a></td> |
|
212 <td>Run a check plugin.</td> |
|
213 </tr> |
|
214 </table> |
|
215 <a NAME="Checker.__init__" ID="Checker.__init__"></a> |
|
216 <h4>Checker (Constructor)</h4> |
|
217 <b>Checker</b>(<i>filename, lines=None</i>) |
|
218 <a NAME="Checker.build_tokens_line" ID="Checker.build_tokens_line"></a> |
|
219 <h4>Checker.build_tokens_line</h4> |
|
220 <b>build_tokens_line</b>(<i></i>) |
|
221 <p> |
|
222 Build a logical line from tokens. |
|
223 </p><a NAME="Checker.check_all" ID="Checker.check_all"></a> |
|
224 <h4>Checker.check_all</h4> |
|
225 <b>check_all</b>(<i>expected=None, line_offset=0</i>) |
|
226 <p> |
|
227 Run all checks on the input file. |
|
228 </p><a NAME="Checker.check_logical" ID="Checker.check_logical"></a> |
|
229 <h4>Checker.check_logical</h4> |
|
230 <b>check_logical</b>(<i></i>) |
|
231 <p> |
|
232 Build a line from tokens and run all logical checks on it. |
|
233 </p><a NAME="Checker.check_physical" ID="Checker.check_physical"></a> |
|
234 <h4>Checker.check_physical</h4> |
|
235 <b>check_physical</b>(<i>line</i>) |
|
236 <p> |
|
237 Run all physical checks on a raw input line. |
|
238 </p><a NAME="Checker.readline" ID="Checker.readline"></a> |
|
239 <h4>Checker.readline</h4> |
|
240 <b>readline</b>(<i></i>) |
|
241 <p> |
|
242 Get the next line from the input buffer. |
|
243 </p><a NAME="Checker.readline_check_physical" ID="Checker.readline_check_physical"></a> |
|
244 <h4>Checker.readline_check_physical</h4> |
|
245 <b>readline_check_physical</b>(<i></i>) |
|
246 <p> |
|
247 Check and return the next physical line. This method can be |
|
248 used to feed tokenize.generate_tokens. |
|
249 </p><a NAME="Checker.report_error" ID="Checker.report_error"></a> |
|
250 <h4>Checker.report_error</h4> |
|
251 <b>report_error</b>(<i>line_number, offset, text, check</i>) |
|
252 <p> |
|
253 Report an error, according to options. |
|
254 </p><a NAME="Checker.run_check" ID="Checker.run_check"></a> |
|
255 <h4>Checker.run_check</h4> |
|
256 <b>run_check</b>(<i>check, argument_names</i>) |
|
257 <p> |
|
258 Run a check plugin. |
|
259 </p> |
|
260 <div align="right"><a href="#top">Up</a></div> |
|
261 <hr /><hr /> |
|
262 <a NAME="_main" ID="_main"></a> |
|
263 <h2>_main</h2> |
|
264 <b>_main</b>(<i></i>) |
|
265 <p> |
|
266 Parse options and run checks on Python source. |
|
267 </p> |
|
268 <div align="right"><a href="#top">Up</a></div> |
|
269 <hr /><hr /> |
|
270 <a NAME="blank_lines" ID="blank_lines"></a> |
|
271 <h2>blank_lines</h2> |
|
272 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level, blank_lines_before_comment</i>) |
|
273 |
|
274 <div align="right"><a href="#top">Up</a></div> |
|
275 <hr /><hr /> |
|
276 <a NAME="compound_statements" ID="compound_statements"></a> |
|
277 <h2>compound_statements</h2> |
|
278 <b>compound_statements</b>(<i>logical_line</i>) |
|
279 |
|
280 <div align="right"><a href="#top">Up</a></div> |
|
281 <hr /><hr /> |
|
282 <a NAME="excluded" ID="excluded"></a> |
|
283 <h2>excluded</h2> |
|
284 <b>excluded</b>(<i>filename</i>) |
|
285 <p> |
|
286 Check if options.exclude contains a pattern that matches filename. |
|
287 </p> |
|
288 <div align="right"><a href="#top">Up</a></div> |
|
289 <hr /><hr /> |
|
290 <a NAME="expand_indent" ID="expand_indent"></a> |
|
291 <h2>expand_indent</h2> |
|
292 <b>expand_indent</b>(<i>line</i>) |
|
293 <p> |
|
294 Return the amount of indentation. |
|
295 Tabs are expanded to the next multiple of 8. |
|
296 </p><p> |
|
297 >>> expand_indent(' ') |
|
298 4 |
|
299 >>> expand_indent('\\t') |
|
300 8 |
|
301 >>> expand_indent(' \\t') |
|
302 8 |
|
303 >>> expand_indent(' \\t') |
|
304 8 |
|
305 >>> expand_indent(' \\t') |
|
306 16 |
|
307 </p> |
|
308 <div align="right"><a href="#top">Up</a></div> |
|
309 <hr /><hr /> |
|
310 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a> |
|
311 <h2>extraneous_whitespace</h2> |
|
312 <b>extraneous_whitespace</b>(<i>logical_line</i>) |
|
313 <p> |
|
314 Avoid extraneous whitespace in the following situations: |
|
315 </p><p> |
|
316 - Immediately inside parentheses, brackets or braces. |
|
317 </p><p> |
|
318 - Immediately before a comma, semicolon, or colon. |
|
319 </p><p> |
|
320 Okay: spam(ham[1], {eggs: 2}) |
|
321 E201: spam( ham[1], {eggs: 2}) |
|
322 E201: spam(ham[ 1], {eggs: 2}) |
|
323 E201: spam(ham[1], { eggs: 2}) |
|
324 E202: spam(ham[1], {eggs: 2} ) |
|
325 E202: spam(ham[1 ], {eggs: 2}) |
|
326 E202: spam(ham[1], {eggs: 2 }) |
|
327 </p><p> |
|
328 E203: if x == 4: print x, y; x, y = y , x |
|
329 E203: if x == 4: print x, y ; x, y = y, x |
|
330 E203: if x == 4 : print x, y; x, y = y, x |
|
331 </p> |
|
332 <div align="right"><a href="#top">Up</a></div> |
|
333 <hr /><hr /> |
|
334 <a NAME="filename_match" ID="filename_match"></a> |
|
335 <h2>filename_match</h2> |
|
336 <b>filename_match</b>(<i>filename</i>) |
|
337 <p> |
|
338 Check if options.filename contains a pattern that matches filename. |
|
339 If options.filename is unspecified, this always returns True. |
|
340 </p> |
|
341 <div align="right"><a href="#top">Up</a></div> |
|
342 <hr /><hr /> |
|
343 <a NAME="find_checks" ID="find_checks"></a> |
|
344 <h2>find_checks</h2> |
|
345 <b>find_checks</b>(<i>argument_name</i>) |
|
346 <p> |
|
347 Find all globally visible functions where the first argument name |
|
348 starts with argument_name. |
|
349 </p> |
|
350 <div align="right"><a href="#top">Up</a></div> |
|
351 <hr /><hr /> |
|
352 <a NAME="get_count" ID="get_count"></a> |
|
353 <h2>get_count</h2> |
|
354 <b>get_count</b>(<i>prefix=''</i>) |
|
355 <p> |
|
356 Return the total count of errors and warnings. |
|
357 </p> |
|
358 <div align="right"><a href="#top">Up</a></div> |
|
359 <hr /><hr /> |
|
360 <a NAME="get_error_statistics" ID="get_error_statistics"></a> |
|
361 <h2>get_error_statistics</h2> |
|
362 <b>get_error_statistics</b>(<i></i>) |
|
363 <p> |
|
364 Get error statistics. |
|
365 </p> |
|
366 <div align="right"><a href="#top">Up</a></div> |
|
367 <hr /><hr /> |
|
368 <a NAME="get_statistics" ID="get_statistics"></a> |
|
369 <h2>get_statistics</h2> |
|
370 <b>get_statistics</b>(<i>prefix=''</i>) |
|
371 <p> |
|
372 Get statistics for message codes that start with the prefix. |
|
373 </p><p> |
|
374 prefix='' matches all errors and warnings |
|
375 prefix='E' matches all errors |
|
376 prefix='W' matches all warnings |
|
377 prefix='E4' matches all errors that have to do with imports |
|
378 </p> |
|
379 <div align="right"><a href="#top">Up</a></div> |
|
380 <hr /><hr /> |
|
381 <a NAME="get_warning_statistics" ID="get_warning_statistics"></a> |
|
382 <h2>get_warning_statistics</h2> |
|
383 <b>get_warning_statistics</b>(<i></i>) |
|
384 <p> |
|
385 Get warning statistics. |
|
386 </p> |
|
387 <div align="right"><a href="#top">Up</a></div> |
|
388 <hr /><hr /> |
|
389 <a NAME="ignore_code" ID="ignore_code"></a> |
|
390 <h2>ignore_code</h2> |
|
391 <b>ignore_code</b>(<i>code</i>) |
|
392 <p> |
|
393 Check if options.ignore contains a prefix of the error code. |
|
394 If options.select contains a prefix of the error code, do not ignore it. |
|
395 </p> |
|
396 <div align="right"><a href="#top">Up</a></div> |
|
397 <hr /><hr /> |
|
398 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a> |
|
399 <h2>imports_on_separate_lines</h2> |
|
400 <b>imports_on_separate_lines</b>(<i>logical_line</i>) |
|
401 |
|
402 <div align="right"><a href="#top">Up</a></div> |
|
403 <hr /><hr /> |
|
404 <a NAME="indentation" ID="indentation"></a> |
|
405 <h2>indentation</h2> |
|
406 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>) |
|
407 |
|
408 <div align="right"><a href="#top">Up</a></div> |
|
409 <hr /><hr /> |
|
410 <a NAME="input_dir" ID="input_dir"></a> |
|
411 <h2>input_dir</h2> |
|
412 <b>input_dir</b>(<i>dirname, runner=None</i>) |
|
413 <p> |
|
414 Check all Python source files in this directory and all subdirectories. |
|
415 </p> |
|
416 <div align="right"><a href="#top">Up</a></div> |
|
417 <hr /><hr /> |
|
418 <a NAME="input_file" ID="input_file"></a> |
|
419 <h2>input_file</h2> |
|
420 <b>input_file</b>(<i>filename</i>) |
|
421 <p> |
|
422 Run all checks on a Python source file. |
|
423 </p> |
|
424 <div align="right"><a href="#top">Up</a></div> |
|
425 <hr /><hr /> |
|
426 <a NAME="maximum_line_length" ID="maximum_line_length"></a> |
|
427 <h2>maximum_line_length</h2> |
|
428 <b>maximum_line_length</b>(<i>physical_line</i>) |
|
429 <p> |
|
430 Limit all lines to a maximum of 79 characters. |
|
431 </p><p> |
|
432 There are still many devices around that are limited to 80 character |
|
433 lines; plus, limiting windows to 80 characters makes it possible to have |
|
434 several windows side-by-side. The default wrapping on such devices looks |
|
435 ugly. Therefore, please limit all lines to a maximum of 79 characters. |
|
436 For flowing long blocks of text (docstrings or comments), limiting the |
|
437 length to 72 characters is recommended. |
|
438 </p> |
|
439 <div align="right"><a href="#top">Up</a></div> |
|
440 <hr /><hr /> |
|
441 <a NAME="message" ID="message"></a> |
|
442 <h2>message</h2> |
|
443 <b>message</b>(<i>text</i>) |
|
444 <p> |
|
445 Print a message. |
|
446 </p> |
|
447 <div align="right"><a href="#top">Up</a></div> |
|
448 <hr /><hr /> |
|
449 <a NAME="missing_newline" ID="missing_newline"></a> |
|
450 <h2>missing_newline</h2> |
|
451 <b>missing_newline</b>(<i>physical_line</i>) |
|
452 <p> |
|
453 JCR: The last line should have a newline. |
|
454 </p> |
|
455 <div align="right"><a href="#top">Up</a></div> |
|
456 <hr /><hr /> |
|
457 <a NAME="missing_whitespace" ID="missing_whitespace"></a> |
|
458 <h2>missing_whitespace</h2> |
|
459 <b>missing_whitespace</b>(<i>logical_line</i>) |
|
460 <p> |
|
461 JCR: Each comma, semicolon or colon should be followed by whitespace. |
|
462 </p><p> |
|
463 Okay: [a, b] |
|
464 Okay: (3,) |
|
465 Okay: a[1:4] |
|
466 Okay: a[:4] |
|
467 Okay: a[1:] |
|
468 Okay: a[1:4:2] |
|
469 E231: ['a','b'] |
|
470 E231: foo(bar,baz) |
|
471 </p> |
|
472 <div align="right"><a href="#top">Up</a></div> |
|
473 <hr /><hr /> |
|
474 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a> |
|
475 <h2>missing_whitespace_around_operator</h2> |
|
476 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>) |
|
477 |
|
478 <div align="right"><a href="#top">Up</a></div> |
|
479 <hr /><hr /> |
|
480 <a NAME="mute_string" ID="mute_string"></a> |
|
481 <h2>mute_string</h2> |
|
482 <b>mute_string</b>(<i>text</i>) |
|
483 <p> |
|
484 Replace contents with 'xxx' to prevent syntax matching. |
|
485 </p><p> |
|
486 >>> mute_string('"abc"') |
|
487 '"xxx"' |
|
488 >>> mute_string("'''abc'''") |
|
489 "'''xxx'''" |
|
490 >>> mute_string("r'abc'") |
|
491 "r'xxx'" |
|
492 </p> |
|
493 <div align="right"><a href="#top">Up</a></div> |
|
494 <hr /><hr /> |
|
495 <a NAME="print_benchmark" ID="print_benchmark"></a> |
|
496 <h2>print_benchmark</h2> |
|
497 <b>print_benchmark</b>(<i>elapsed</i>) |
|
498 <p> |
|
499 Print benchmark numbers. |
|
500 </p> |
|
501 <div align="right"><a href="#top">Up</a></div> |
|
502 <hr /><hr /> |
|
503 <a NAME="print_statistics" ID="print_statistics"></a> |
|
504 <h2>print_statistics</h2> |
|
505 <b>print_statistics</b>(<i>prefix=''</i>) |
|
506 <p> |
|
507 Print overall statistics (number of errors and warnings). |
|
508 </p> |
|
509 <div align="right"><a href="#top">Up</a></div> |
|
510 <hr /><hr /> |
|
511 <a NAME="process_options" ID="process_options"></a> |
|
512 <h2>process_options</h2> |
|
513 <b>process_options</b>(<i>arglist=None</i>) |
|
514 <p> |
|
515 Process options passed either via arglist or via command line args. |
|
516 </p> |
|
517 <div align="right"><a href="#top">Up</a></div> |
|
518 <hr /><hr /> |
|
519 <a NAME="python_3000_backticks" ID="python_3000_backticks"></a> |
|
520 <h2>python_3000_backticks</h2> |
|
521 <b>python_3000_backticks</b>(<i>logical_line</i>) |
|
522 <p> |
|
523 Backticks are removed in Python 3000. |
|
524 Use repr() instead. |
|
525 </p> |
|
526 <div align="right"><a href="#top">Up</a></div> |
|
527 <hr /><hr /> |
|
528 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a> |
|
529 <h2>python_3000_has_key</h2> |
|
530 <b>python_3000_has_key</b>(<i>logical_line</i>) |
|
531 <p> |
|
532 The {}.has_key() method will be removed in the future version of |
|
533 Python. Use the 'in' operation instead, like: |
|
534 d = {"a": 1, "b": 2} |
|
535 if "b" in d: |
|
536 print d["b"] |
|
537 </p> |
|
538 <div align="right"><a href="#top">Up</a></div> |
|
539 <hr /><hr /> |
|
540 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a> |
|
541 <h2>python_3000_not_equal</h2> |
|
542 <b>python_3000_not_equal</b>(<i>logical_line</i>) |
|
543 <p> |
|
544 != can also be written <>, but this is an obsolete usage kept for |
|
545 backwards compatibility only. New code should always use !=. |
|
546 The older syntax is removed in Python 3000. |
|
547 </p> |
|
548 <div align="right"><a href="#top">Up</a></div> |
|
549 <hr /><hr /> |
|
550 <a NAME="python_3000_raise_comma" ID="python_3000_raise_comma"></a> |
|
551 <h2>python_3000_raise_comma</h2> |
|
552 <b>python_3000_raise_comma</b>(<i>logical_line</i>) |
|
553 <p> |
|
554 When raising an exception, use "raise ValueError('message')" |
|
555 instead of the older form "raise ValueError, 'message'". |
|
556 </p><p> |
|
557 The paren-using form is preferred because when the exception arguments |
|
558 are long or include string formatting, you don't need to use line |
|
559 continuation characters thanks to the containing parentheses. The older |
|
560 form will be removed in Python 3000. |
|
561 </p> |
|
562 <div align="right"><a href="#top">Up</a></div> |
|
563 <hr /><hr /> |
|
564 <a NAME="readlines" ID="readlines"></a> |
|
565 <h2>readlines</h2> |
|
566 <b>readlines</b>(<i>filename</i>) |
|
567 |
|
568 <div align="right"><a href="#top">Up</a></div> |
|
569 <hr /><hr /> |
|
570 <a NAME="readlines_1" ID="readlines_1"></a> |
|
571 <h2>readlines</h2> |
|
572 <b>readlines</b>(<i>filename</i>) |
|
573 |
|
574 <div align="right"><a href="#top">Up</a></div> |
|
575 <hr /><hr /> |
|
576 <a NAME="reset_counters" ID="reset_counters"></a> |
|
577 <h2>reset_counters</h2> |
|
578 <b>reset_counters</b>(<i></i>) |
|
579 |
|
580 <div align="right"><a href="#top">Up</a></div> |
|
581 <hr /><hr /> |
|
582 <a NAME="run_tests" ID="run_tests"></a> |
|
583 <h2>run_tests</h2> |
|
584 <b>run_tests</b>(<i>filename</i>) |
|
585 <p> |
|
586 Run all the tests from a file. |
|
587 </p><p> |
|
588 A test file can provide many tests. Each test starts with a declaration. |
|
589 This declaration is a single line starting with '#:'. |
|
590 It declares codes of expected failures, separated by spaces or 'Okay' |
|
591 if no failure is expected. |
|
592 If the file does not contain such declaration, it should pass all tests. |
|
593 If the declaration is empty, following lines are not checked, until next |
|
594 declaration. |
|
595 </p><p> |
|
596 Examples: |
|
597 </p><p> |
|
598 * Only E224 and W701 are expected: #: E224 W701 |
|
599 * Following example is conform: #: Okay |
|
600 * Don't check these lines: #: |
|
601 </p> |
|
602 <div align="right"><a href="#top">Up</a></div> |
|
603 <hr /><hr /> |
|
604 <a NAME="selftest" ID="selftest"></a> |
|
605 <h2>selftest</h2> |
|
606 <b>selftest</b>(<i></i>) |
|
607 <p> |
|
608 Test all check functions with test cases in docstrings. |
|
609 </p> |
|
610 <div align="right"><a href="#top">Up</a></div> |
|
611 <hr /><hr /> |
|
612 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a> |
|
613 <h2>tabs_obsolete</h2> |
|
614 <b>tabs_obsolete</b>(<i>physical_line</i>) |
|
615 |
|
616 <div align="right"><a href="#top">Up</a></div> |
|
617 <hr /><hr /> |
|
618 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a> |
|
619 <h2>tabs_or_spaces</h2> |
|
620 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>) |
|
621 |
|
622 <div align="right"><a href="#top">Up</a></div> |
|
623 <hr /><hr /> |
|
624 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a> |
|
625 <h2>trailing_blank_lines</h2> |
|
626 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>) |
|
627 |
|
628 <div align="right"><a href="#top">Up</a></div> |
|
629 <hr /><hr /> |
|
630 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a> |
|
631 <h2>trailing_whitespace</h2> |
|
632 <b>trailing_whitespace</b>(<i>physical_line</i>) |
|
633 |
|
634 <div align="right"><a href="#top">Up</a></div> |
|
635 <hr /><hr /> |
|
636 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a> |
|
637 <h2>whitespace_around_comma</h2> |
|
638 <b>whitespace_around_comma</b>(<i>logical_line</i>) |
|
639 <p> |
|
640 Avoid extraneous whitespace in the following situations: |
|
641 </p><p> |
|
642 - More than one space around an assignment (or other) operator to |
|
643 align it with another. |
|
644 </p><p> |
|
645 JCR: This should also be applied around comma etc. |
|
646 Note: these checks are disabled by default |
|
647 </p><p> |
|
648 Okay: a = (1, 2) |
|
649 E241: a = (1, 2) |
|
650 E242: a = (1,\t2) |
|
651 </p> |
|
652 <div align="right"><a href="#top">Up</a></div> |
|
653 <hr /><hr /> |
|
654 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a> |
|
655 <h2>whitespace_around_named_parameter_equals</h2> |
|
656 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line</i>) |
|
657 <p> |
|
658 Don't use spaces around the '=' sign when used to indicate a |
|
659 keyword argument or a default parameter value. |
|
660 </p><p> |
|
661 Okay: def complex(real, imag=0.0): |
|
662 Okay: return magic(r=real, i=imag) |
|
663 Okay: boolean(a == b) |
|
664 Okay: boolean(a != b) |
|
665 Okay: boolean(a <= b) |
|
666 Okay: boolean(a >= b) |
|
667 </p><p> |
|
668 E251: def complex(real, imag = 0.0): |
|
669 E251: return magic(r = real, i = imag) |
|
670 </p> |
|
671 <div align="right"><a href="#top">Up</a></div> |
|
672 <hr /><hr /> |
|
673 <a NAME="whitespace_around_operator" ID="whitespace_around_operator"></a> |
|
674 <h2>whitespace_around_operator</h2> |
|
675 <b>whitespace_around_operator</b>(<i>logical_line</i>) |
|
676 <p> |
|
677 Avoid extraneous whitespace in the following situations: |
|
678 </p><p> |
|
679 - More than one space around an assignment (or other) operator to |
|
680 align it with another. |
|
681 </p><p> |
|
682 Okay: a = 12 + 3 |
|
683 E221: a = 4 + 5 |
|
684 E222: a = 4 + 5 |
|
685 E223: a = 4\t+ 5 |
|
686 E224: a = 4 +\t5 |
|
687 </p> |
|
688 <div align="right"><a href="#top">Up</a></div> |
|
689 <hr /><hr /> |
|
690 <a NAME="whitespace_before_inline_comment" ID="whitespace_before_inline_comment"></a> |
|
691 <h2>whitespace_before_inline_comment</h2> |
|
692 <b>whitespace_before_inline_comment</b>(<i>logical_line, tokens</i>) |
|
693 <p> |
|
694 Separate inline comments by at least two spaces. |
|
695 </p><p> |
|
696 An inline comment is a comment on the same line as a statement. Inline |
|
697 comments should be separated by at least two spaces from the statement. |
|
698 They should start with a # and a single space. |
|
699 </p><p> |
|
700 Okay: x = x + 1 # Increment x |
|
701 Okay: x = x + 1 # Increment x |
|
702 E261: x = x + 1 # Increment x |
|
703 E262: x = x + 1 #Increment x |
|
704 E262: x = x + 1 # Increment x |
|
705 </p> |
|
706 <div align="right"><a href="#top">Up</a></div> |
|
707 <hr /><hr /> |
|
708 <a NAME="whitespace_before_parameters" ID="whitespace_before_parameters"></a> |
|
709 <h2>whitespace_before_parameters</h2> |
|
710 <b>whitespace_before_parameters</b>(<i>logical_line, tokens</i>) |
|
711 <p> |
|
712 Avoid extraneous whitespace in the following situations: |
|
713 </p><p> |
|
714 - Immediately before the open parenthesis that starts the argument |
|
715 list of a function call. |
|
716 </p><p> |
|
717 - Immediately before the open parenthesis that starts an indexing or |
|
718 slicing. |
|
719 </p><p> |
|
720 Okay: spam(1) |
|
721 E211: spam (1) |
|
722 </p><p> |
|
723 Okay: dict['key'] = list[index] |
|
724 E211: dict ['key'] = list[index] |
|
725 E211: dict['key'] = list [index] |
|
726 </p> |
|
727 <div align="right"><a href="#top">Up</a></div> |
|
728 <hr /> |
|
729 </body></html> |