Documentation/Source/eric5.UtilitiesPython2.pep8.html

branch
Py2 comp.
changeset 3456
96232974dcdb
parent 3178
f25fc1364c88
parent 3445
bf95eac5ce12
child 3484
645c12de6b0c
equal deleted inserted replaced
3178:f25fc1364c88 3456:96232974dcdb
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric5.UtilitiesPython2.pep8</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.pep8</h1>
23
24 <h3>Global Attributes</h3>
25 <table>
26 <tr><td>ARITHMETIC_OP</td></tr><tr><td>BENCHMARK_KEYS</td></tr><tr><td>COMMENT_WITH_NL</td></tr><tr><td>COMPARE_SINGLETON_REGEX</td></tr><tr><td>COMPARE_TYPE_REGEX</td></tr><tr><td>DEFAULT_EXCLUDE</td></tr><tr><td>DEFAULT_IGNORE</td></tr><tr><td>DOCSTRING_REGEX</td></tr><tr><td>ERRORCODE_REGEX</td></tr><tr><td>EXTRANEOUS_WHITESPACE_REGEX</td></tr><tr><td>HUNK_REGEX</td></tr><tr><td>INDENT_REGEX</td></tr><tr><td>KEYWORDS</td></tr><tr><td>KEYWORD_REGEX</td></tr><tr><td>LAMBDA_REGEX</td></tr><tr><td>MAX_LINE_LENGTH</td></tr><tr><td>OPERATOR_REGEX</td></tr><tr><td>PROJECT_CONFIG</td></tr><tr><td>PyCF_ONLY_AST</td></tr><tr><td>RAISE_COMMA_REGEX</td></tr><tr><td>REPORT_FORMAT</td></tr><tr><td>RERAISE_COMMA_REGEX</td></tr><tr><td>SINGLETONS</td></tr><tr><td>SKIP_TOKENS</td></tr><tr><td>TESTSUITE_PATH</td></tr><tr><td>UNARY_OPERATORS</td></tr><tr><td>WHITESPACE</td></tr><tr><td>WHITESPACE_AFTER_COMMA_REGEX</td></tr><tr><td>WS_NEEDED_OPERATORS</td></tr><tr><td>WS_OPTIONAL_OPERATORS</td></tr><tr><td>__version__</td></tr><tr><td>_checks</td></tr><tr><td>noqa</td></tr>
27 </table>
28 <h3>Classes</h3>
29 <table>
30 <tr>
31 <td><a href="#BaseReport">BaseReport</a></td>
32 <td>Collect the results of the checks.</td>
33 </tr><tr>
34 <td><a href="#Checker">Checker</a></td>
35 <td>Load a Python source file, tokenize it, check coding style.</td>
36 </tr><tr>
37 <td><a href="#DiffReport">DiffReport</a></td>
38 <td>Collect and print the results for the changed lines only.</td>
39 </tr><tr>
40 <td><a href="#FileReport">FileReport</a></td>
41 <td>Collect the results of the checks and print only the filenames.</td>
42 </tr><tr>
43 <td><a href="#StandardReport">StandardReport</a></td>
44 <td>Collect and print the results of the checks.</td>
45 </tr><tr>
46 <td><a href="#StyleGuide">StyleGuide</a></td>
47 <td>Initialize a PEP-8 instance with few options.</td>
48 </tr>
49 </table>
50 <h3>Functions</h3>
51 <table>
52 <tr>
53 <td><a href="#_add_check">_add_check</a></td>
54 <td></td>
55 </tr><tr>
56 <td><a href="#_main">_main</a></td>
57 <td>Parse options and run checks on Python source.</td>
58 </tr><tr>
59 <td><a href="#blank_lines">blank_lines</a></td>
60 <td>Separate top-level function and class definitions with two blank lines.</td>
61 </tr><tr>
62 <td><a href="#comparison_to_singleton">comparison_to_singleton</a></td>
63 <td>Comparisons to singletons like None should always be done with "is" or "is not", never the equality operators.</td>
64 </tr><tr>
65 <td><a href="#comparison_type">comparison_type</a></td>
66 <td>Object type comparisons should always use isinstance() instead of comparing types directly.</td>
67 </tr><tr>
68 <td><a href="#compound_statements">compound_statements</a></td>
69 <td>Compound statements (multiple statements on the same line) are generally discouraged.</td>
70 </tr><tr>
71 <td><a href="#continued_indentation">continued_indentation</a></td>
72 <td>Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent.</td>
73 </tr><tr>
74 <td><a href="#expand_indent">expand_indent</a></td>
75 <td>Return the amount of indentation.</td>
76 </tr><tr>
77 <td><a href="#explicit_line_join">explicit_line_join</a></td>
78 <td>Avoid explicit line join between brackets.</td>
79 </tr><tr>
80 <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td>
81 <td>Avoid extraneous whitespace in the following situations:</td>
82 </tr><tr>
83 <td><a href="#filename_match">filename_match</a></td>
84 <td>Check if patterns contains a pattern that matches filename.</td>
85 </tr><tr>
86 <td><a href="#get_parser">get_parser</a></td>
87 <td></td>
88 </tr><tr>
89 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td>
90 <td>Imports should usually be on separate lines.</td>
91 </tr><tr>
92 <td><a href="#indentation">indentation</a></td>
93 <td>Use 4 spaces per indentation level.</td>
94 </tr><tr>
95 <td><a href="#init_checks_registry">init_checks_registry</a></td>
96 <td>Register all globally visible functions where the first argument name is 'physical_line' or 'logical_line'.</td>
97 </tr><tr>
98 <td><a href="#maximum_line_length">maximum_line_length</a></td>
99 <td>Limit all lines to a maximum of 79 characters.</td>
100 </tr><tr>
101 <td><a href="#missing_newline">missing_newline</a></td>
102 <td>JCR: The last line should have a newline.</td>
103 </tr><tr>
104 <td><a href="#missing_whitespace">missing_whitespace</a></td>
105 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td>
106 </tr><tr>
107 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td>
108 <td>- Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).</td>
109 </tr><tr>
110 <td><a href="#mute_string">mute_string</a></td>
111 <td>Replace contents with 'xxx' to prevent syntax matching.</td>
112 </tr><tr>
113 <td><a href="#parse_udiff">parse_udiff</a></td>
114 <td>Return a dictionary of matching lines.</td>
115 </tr><tr>
116 <td><a href="#process_options">process_options</a></td>
117 <td>Process options passed either via arglist or via command line args.</td>
118 </tr><tr>
119 <td><a href="#python_3000_backticks">python_3000_backticks</a></td>
120 <td>Backticks are removed in Python 3.</td>
121 </tr><tr>
122 <td><a href="#python_3000_has_key">python_3000_has_key</a></td>
123 <td>The {}.has_key() method is removed in the Python 3.</td>
124 </tr><tr>
125 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td>
126 <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td>
127 </tr><tr>
128 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td>
129 <td>When raising an exception, use "raise ValueError('message')" instead of the older form "raise ValueError, 'message'".</td>
130 </tr><tr>
131 <td><a href="#read_config">read_config</a></td>
132 <td>Read both user configuration and local configuration.</td>
133 </tr><tr>
134 <td><a href="#readlines">readlines</a></td>
135 <td></td>
136 </tr><tr>
137 <td><a href="#readlines_1">readlines</a></td>
138 <td></td>
139 </tr><tr>
140 <td><a href="#register_check">register_check</a></td>
141 <td>Register a new check object.</td>
142 </tr><tr>
143 <td><a href="#stdin_get_value">stdin_get_value</a></td>
144 <td></td>
145 </tr><tr>
146 <td><a href="#tabs_obsolete">tabs_obsolete</a></td>
147 <td>For new projects, spaces-only are strongly recommended over tabs.</td>
148 </tr><tr>
149 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td>
150 <td>Never mix tabs and spaces.</td>
151 </tr><tr>
152 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td>
153 <td>JCR: Trailing blank lines are superfluous.</td>
154 </tr><tr>
155 <td><a href="#trailing_whitespace">trailing_whitespace</a></td>
156 <td>JCR: Trailing whitespace is superfluous.</td>
157 </tr><tr>
158 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td>
159 <td>Avoid extraneous whitespace in the following situations:</td>
160 </tr><tr>
161 <td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td>
162 <td>Avoid extraneous whitespace around keywords.</td>
163 </tr><tr>
164 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td>
165 <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td>
166 </tr><tr>
167 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td>
168 <td>Avoid extraneous whitespace in the following situations:</td>
169 </tr><tr>
170 <td><a href="#whitespace_before_inline_comment">whitespace_before_inline_comment</a></td>
171 <td>Separate inline comments by at least two spaces.</td>
172 </tr><tr>
173 <td><a href="#whitespace_before_parameters">whitespace_before_parameters</a></td>
174 <td>Avoid extraneous whitespace in the following situations:</td>
175 </tr>
176 </table>
177 <hr /><hr />
178 <a NAME="BaseReport" ID="BaseReport"></a>
179 <h2>BaseReport</h2>
180 <p>
181 Collect the results of the checks.
182 </p>
183 <h3>Derived from</h3>
184 object
185 <h3>Class Attributes</h3>
186 <table>
187 <tr><td>print_filename</td></tr>
188 </table>
189 <h3>Class Methods</h3>
190 <table>
191 <tr><td>None</td></tr>
192 </table>
193 <h3>Methods</h3>
194 <table>
195 <tr>
196 <td><a href="#BaseReport.__init__">BaseReport</a></td>
197 <td></td>
198 </tr><tr>
199 <td><a href="#BaseReport.error">error</a></td>
200 <td>Report an error, according to options.</td>
201 </tr><tr>
202 <td><a href="#BaseReport.error_args">error_args</a></td>
203 <td>Report an error, according to options.</td>
204 </tr><tr>
205 <td><a href="#BaseReport.get_count">get_count</a></td>
206 <td>Return the total count of errors and warnings.</td>
207 </tr><tr>
208 <td><a href="#BaseReport.get_file_results">get_file_results</a></td>
209 <td>Return the count of errors and warnings for this file.</td>
210 </tr><tr>
211 <td><a href="#BaseReport.get_statistics">get_statistics</a></td>
212 <td>Get statistics for message codes that start with the prefix.</td>
213 </tr><tr>
214 <td><a href="#BaseReport.increment_logical_line">increment_logical_line</a></td>
215 <td>Signal a new logical line.</td>
216 </tr><tr>
217 <td><a href="#BaseReport.init_file">init_file</a></td>
218 <td>Signal a new file.</td>
219 </tr><tr>
220 <td><a href="#BaseReport.print_benchmark">print_benchmark</a></td>
221 <td>Print benchmark numbers.</td>
222 </tr><tr>
223 <td><a href="#BaseReport.print_statistics">print_statistics</a></td>
224 <td>Print overall statistics (number of errors and warnings).</td>
225 </tr><tr>
226 <td><a href="#BaseReport.start">start</a></td>
227 <td>Start the timer.</td>
228 </tr><tr>
229 <td><a href="#BaseReport.stop">stop</a></td>
230 <td>Stop the timer.</td>
231 </tr>
232 </table>
233 <h3>Static Methods</h3>
234 <table>
235 <tr><td>None</td></tr>
236 </table>
237 <a NAME="BaseReport.__init__" ID="BaseReport.__init__"></a>
238 <h4>BaseReport (Constructor)</h4>
239 <b>BaseReport</b>(<i>options</i>)
240 <a NAME="BaseReport.error" ID="BaseReport.error"></a>
241 <h4>BaseReport.error</h4>
242 <b>error</b>(<i>line_number, offset, text, check</i>)
243 <p>
244 Report an error, according to options.
245 </p><a NAME="BaseReport.error_args" ID="BaseReport.error_args"></a>
246 <h4>BaseReport.error_args</h4>
247 <b>error_args</b>(<i>line_number, offset, code, check, *args</i>)
248 <p>
249 Report an error, according to options.
250 </p><a NAME="BaseReport.get_count" ID="BaseReport.get_count"></a>
251 <h4>BaseReport.get_count</h4>
252 <b>get_count</b>(<i>prefix=''</i>)
253 <p>
254 Return the total count of errors and warnings.
255 </p><a NAME="BaseReport.get_file_results" ID="BaseReport.get_file_results"></a>
256 <h4>BaseReport.get_file_results</h4>
257 <b>get_file_results</b>(<i></i>)
258 <p>
259 Return the count of errors and warnings for this file.
260 </p><a NAME="BaseReport.get_statistics" ID="BaseReport.get_statistics"></a>
261 <h4>BaseReport.get_statistics</h4>
262 <b>get_statistics</b>(<i>prefix=''</i>)
263 <p>
264 Get statistics for message codes that start with the prefix.
265 </p><p>
266 prefix='' matches all errors and warnings
267 prefix='E' matches all errors
268 prefix='W' matches all warnings
269 prefix='E4' matches all errors that have to do with imports
270 </p><a NAME="BaseReport.increment_logical_line" ID="BaseReport.increment_logical_line"></a>
271 <h4>BaseReport.increment_logical_line</h4>
272 <b>increment_logical_line</b>(<i></i>)
273 <p>
274 Signal a new logical line.
275 </p><a NAME="BaseReport.init_file" ID="BaseReport.init_file"></a>
276 <h4>BaseReport.init_file</h4>
277 <b>init_file</b>(<i>filename, lines, expected, line_offset</i>)
278 <p>
279 Signal a new file.
280 </p><a NAME="BaseReport.print_benchmark" ID="BaseReport.print_benchmark"></a>
281 <h4>BaseReport.print_benchmark</h4>
282 <b>print_benchmark</b>(<i></i>)
283 <p>
284 Print benchmark numbers.
285 </p><a NAME="BaseReport.print_statistics" ID="BaseReport.print_statistics"></a>
286 <h4>BaseReport.print_statistics</h4>
287 <b>print_statistics</b>(<i>prefix=''</i>)
288 <p>
289 Print overall statistics (number of errors and warnings).
290 </p><a NAME="BaseReport.start" ID="BaseReport.start"></a>
291 <h4>BaseReport.start</h4>
292 <b>start</b>(<i></i>)
293 <p>
294 Start the timer.
295 </p><a NAME="BaseReport.stop" ID="BaseReport.stop"></a>
296 <h4>BaseReport.stop</h4>
297 <b>stop</b>(<i></i>)
298 <p>
299 Stop the timer.
300 </p>
301 <div align="right"><a href="#top">Up</a></div>
302 <hr /><hr />
303 <a NAME="Checker" ID="Checker"></a>
304 <h2>Checker</h2>
305 <p>
306 Load a Python source file, tokenize it, check coding style.
307 </p>
308 <h3>Derived from</h3>
309 object
310 <h3>Class Attributes</h3>
311 <table>
312 <tr><td>None</td></tr>
313 </table>
314 <h3>Class Methods</h3>
315 <table>
316 <tr><td>None</td></tr>
317 </table>
318 <h3>Methods</h3>
319 <table>
320 <tr>
321 <td><a href="#Checker.__init__">Checker</a></td>
322 <td></td>
323 </tr><tr>
324 <td><a href="#Checker.build_tokens_line">build_tokens_line</a></td>
325 <td>Build a logical line from tokens.</td>
326 </tr><tr>
327 <td><a href="#Checker.check_all">check_all</a></td>
328 <td>Run all checks on the input file.</td>
329 </tr><tr>
330 <td><a href="#Checker.check_ast">check_ast</a></td>
331 <td></td>
332 </tr><tr>
333 <td><a href="#Checker.check_logical">check_logical</a></td>
334 <td>Build a line from tokens and run all logical checks on it.</td>
335 </tr><tr>
336 <td><a href="#Checker.check_physical">check_physical</a></td>
337 <td>Run all physical checks on a raw input line.</td>
338 </tr><tr>
339 <td><a href="#Checker.generate_tokens">generate_tokens</a></td>
340 <td></td>
341 </tr><tr>
342 <td><a href="#Checker.readline">readline</a></td>
343 <td>Get the next line from the input buffer.</td>
344 </tr><tr>
345 <td><a href="#Checker.readline_check_physical">readline_check_physical</a></td>
346 <td>Check and return the next physical line.</td>
347 </tr><tr>
348 <td><a href="#Checker.report_invalid_syntax">report_invalid_syntax</a></td>
349 <td></td>
350 </tr><tr>
351 <td><a href="#Checker.run_check">run_check</a></td>
352 <td>Run a check plugin.</td>
353 </tr>
354 </table>
355 <h3>Static Methods</h3>
356 <table>
357 <tr><td>None</td></tr>
358 </table>
359 <a NAME="Checker.__init__" ID="Checker.__init__"></a>
360 <h4>Checker (Constructor)</h4>
361 <b>Checker</b>(<i>filename=None, lines=None, options=None, report=None, **kwargs</i>)
362 <a NAME="Checker.build_tokens_line" ID="Checker.build_tokens_line"></a>
363 <h4>Checker.build_tokens_line</h4>
364 <b>build_tokens_line</b>(<i></i>)
365 <p>
366 Build a logical line from tokens.
367 </p><a NAME="Checker.check_all" ID="Checker.check_all"></a>
368 <h4>Checker.check_all</h4>
369 <b>check_all</b>(<i>expected=None, line_offset=0</i>)
370 <p>
371 Run all checks on the input file.
372 </p><a NAME="Checker.check_ast" ID="Checker.check_ast"></a>
373 <h4>Checker.check_ast</h4>
374 <b>check_ast</b>(<i></i>)
375 <a NAME="Checker.check_logical" ID="Checker.check_logical"></a>
376 <h4>Checker.check_logical</h4>
377 <b>check_logical</b>(<i></i>)
378 <p>
379 Build a line from tokens and run all logical checks on it.
380 </p><a NAME="Checker.check_physical" ID="Checker.check_physical"></a>
381 <h4>Checker.check_physical</h4>
382 <b>check_physical</b>(<i>line</i>)
383 <p>
384 Run all physical checks on a raw input line.
385 </p><a NAME="Checker.generate_tokens" ID="Checker.generate_tokens"></a>
386 <h4>Checker.generate_tokens</h4>
387 <b>generate_tokens</b>(<i></i>)
388 <a NAME="Checker.readline" ID="Checker.readline"></a>
389 <h4>Checker.readline</h4>
390 <b>readline</b>(<i></i>)
391 <p>
392 Get the next line from the input buffer.
393 </p><a NAME="Checker.readline_check_physical" ID="Checker.readline_check_physical"></a>
394 <h4>Checker.readline_check_physical</h4>
395 <b>readline_check_physical</b>(<i></i>)
396 <p>
397 Check and return the next physical line. This method can be
398 used to feed tokenize.generate_tokens.
399 </p><a NAME="Checker.report_invalid_syntax" ID="Checker.report_invalid_syntax"></a>
400 <h4>Checker.report_invalid_syntax</h4>
401 <b>report_invalid_syntax</b>(<i></i>)
402 <a NAME="Checker.run_check" ID="Checker.run_check"></a>
403 <h4>Checker.run_check</h4>
404 <b>run_check</b>(<i>check, argument_names</i>)
405 <p>
406 Run a check plugin.
407 </p>
408 <div align="right"><a href="#top">Up</a></div>
409 <hr /><hr />
410 <a NAME="DiffReport" ID="DiffReport"></a>
411 <h2>DiffReport</h2>
412 <p>
413 Collect and print the results for the changed lines only.
414 </p>
415 <h3>Derived from</h3>
416 StandardReport
417 <h3>Class Attributes</h3>
418 <table>
419 <tr><td>None</td></tr>
420 </table>
421 <h3>Class Methods</h3>
422 <table>
423 <tr><td>None</td></tr>
424 </table>
425 <h3>Methods</h3>
426 <table>
427 <tr>
428 <td><a href="#DiffReport.__init__">DiffReport</a></td>
429 <td></td>
430 </tr><tr>
431 <td><a href="#DiffReport.error">error</a></td>
432 <td></td>
433 </tr>
434 </table>
435 <h3>Static Methods</h3>
436 <table>
437 <tr><td>None</td></tr>
438 </table>
439 <a NAME="DiffReport.__init__" ID="DiffReport.__init__"></a>
440 <h4>DiffReport (Constructor)</h4>
441 <b>DiffReport</b>(<i>options</i>)
442 <a NAME="DiffReport.error" ID="DiffReport.error"></a>
443 <h4>DiffReport.error</h4>
444 <b>error</b>(<i>line_number, offset, text, check</i>)
445
446 <div align="right"><a href="#top">Up</a></div>
447 <hr /><hr />
448 <a NAME="FileReport" ID="FileReport"></a>
449 <h2>FileReport</h2>
450 <p>
451 Collect the results of the checks and print only the filenames.
452 </p>
453 <h3>Derived from</h3>
454 BaseReport
455 <h3>Class Attributes</h3>
456 <table>
457 <tr><td>print_filename</td></tr>
458 </table>
459 <h3>Class Methods</h3>
460 <table>
461 <tr><td>None</td></tr>
462 </table>
463 <h3>Methods</h3>
464 <table>
465 <tr><td>None</td></tr>
466 </table>
467 <h3>Static Methods</h3>
468 <table>
469 <tr><td>None</td></tr>
470 </table>
471
472 <div align="right"><a href="#top">Up</a></div>
473 <hr /><hr />
474 <a NAME="StandardReport" ID="StandardReport"></a>
475 <h2>StandardReport</h2>
476 <p>
477 Collect and print the results of the checks.
478 </p>
479 <h3>Derived from</h3>
480 BaseReport
481 <h3>Class Attributes</h3>
482 <table>
483 <tr><td>None</td></tr>
484 </table>
485 <h3>Class Methods</h3>
486 <table>
487 <tr><td>None</td></tr>
488 </table>
489 <h3>Methods</h3>
490 <table>
491 <tr>
492 <td><a href="#StandardReport.__init__">StandardReport</a></td>
493 <td></td>
494 </tr><tr>
495 <td><a href="#StandardReport.error">error</a></td>
496 <td>Report an error, according to options.</td>
497 </tr><tr>
498 <td><a href="#StandardReport.error_args">error_args</a></td>
499 <td>Report an error, according to options.</td>
500 </tr><tr>
501 <td><a href="#StandardReport.get_file_results">get_file_results</a></td>
502 <td>Print the result and return the overall count for this file.</td>
503 </tr><tr>
504 <td><a href="#StandardReport.init_file">init_file</a></td>
505 <td>Signal a new file.</td>
506 </tr>
507 </table>
508 <h3>Static Methods</h3>
509 <table>
510 <tr><td>None</td></tr>
511 </table>
512 <a NAME="StandardReport.__init__" ID="StandardReport.__init__"></a>
513 <h4>StandardReport (Constructor)</h4>
514 <b>StandardReport</b>(<i>options</i>)
515 <a NAME="StandardReport.error" ID="StandardReport.error"></a>
516 <h4>StandardReport.error</h4>
517 <b>error</b>(<i>line_number, offset, text, check</i>)
518 <p>
519 Report an error, according to options.
520 </p><a NAME="StandardReport.error_args" ID="StandardReport.error_args"></a>
521 <h4>StandardReport.error_args</h4>
522 <b>error_args</b>(<i>line_number, offset, code, check, *args</i>)
523 <p>
524 Report an error, according to options.
525 </p><a NAME="StandardReport.get_file_results" ID="StandardReport.get_file_results"></a>
526 <h4>StandardReport.get_file_results</h4>
527 <b>get_file_results</b>(<i></i>)
528 <p>
529 Print the result and return the overall count for this file.
530 </p><a NAME="StandardReport.init_file" ID="StandardReport.init_file"></a>
531 <h4>StandardReport.init_file</h4>
532 <b>init_file</b>(<i>filename, lines, expected, line_offset</i>)
533 <p>
534 Signal a new file.
535 </p>
536 <div align="right"><a href="#top">Up</a></div>
537 <hr /><hr />
538 <a NAME="StyleGuide" ID="StyleGuide"></a>
539 <h2>StyleGuide</h2>
540 <p>
541 Initialize a PEP-8 instance with few options.
542 </p>
543 <h3>Derived from</h3>
544 object
545 <h3>Class Attributes</h3>
546 <table>
547 <tr><td>None</td></tr>
548 </table>
549 <h3>Class Methods</h3>
550 <table>
551 <tr><td>None</td></tr>
552 </table>
553 <h3>Methods</h3>
554 <table>
555 <tr>
556 <td><a href="#StyleGuide.__init__">StyleGuide</a></td>
557 <td></td>
558 </tr><tr>
559 <td><a href="#StyleGuide.check_files">check_files</a></td>
560 <td>Run all checks on the paths.</td>
561 </tr><tr>
562 <td><a href="#StyleGuide.excluded">excluded</a></td>
563 <td>Check if options.exclude contains a pattern that matches filename.</td>
564 </tr><tr>
565 <td><a href="#StyleGuide.get_checks">get_checks</a></td>
566 <td>Find all globally visible functions where the first argument name starts with argument_name and which contain selected tests.</td>
567 </tr><tr>
568 <td><a href="#StyleGuide.ignore_code">ignore_code</a></td>
569 <td>Check if the error code should be ignored.</td>
570 </tr><tr>
571 <td><a href="#StyleGuide.init_report">init_report</a></td>
572 <td>Initialize the report instance.</td>
573 </tr><tr>
574 <td><a href="#StyleGuide.input_dir">input_dir</a></td>
575 <td>Check all files in this directory and all subdirectories.</td>
576 </tr><tr>
577 <td><a href="#StyleGuide.input_file">input_file</a></td>
578 <td>Run all checks on a Python source file.</td>
579 </tr>
580 </table>
581 <h3>Static Methods</h3>
582 <table>
583 <tr><td>None</td></tr>
584 </table>
585 <a NAME="StyleGuide.__init__" ID="StyleGuide.__init__"></a>
586 <h4>StyleGuide (Constructor)</h4>
587 <b>StyleGuide</b>(<i>*args, **kwargs</i>)
588 <a NAME="StyleGuide.check_files" ID="StyleGuide.check_files"></a>
589 <h4>StyleGuide.check_files</h4>
590 <b>check_files</b>(<i>paths=None</i>)
591 <p>
592 Run all checks on the paths.
593 </p><a NAME="StyleGuide.excluded" ID="StyleGuide.excluded"></a>
594 <h4>StyleGuide.excluded</h4>
595 <b>excluded</b>(<i>filename, parent=None</i>)
596 <p>
597 Check if options.exclude contains a pattern that matches filename.
598 </p><a NAME="StyleGuide.get_checks" ID="StyleGuide.get_checks"></a>
599 <h4>StyleGuide.get_checks</h4>
600 <b>get_checks</b>(<i>argument_name</i>)
601 <p>
602 Find all globally visible functions where the first argument name
603 starts with argument_name and which contain selected tests.
604 </p><a NAME="StyleGuide.ignore_code" ID="StyleGuide.ignore_code"></a>
605 <h4>StyleGuide.ignore_code</h4>
606 <b>ignore_code</b>(<i>code</i>)
607 <p>
608 Check if the error code should be ignored.
609 </p><p>
610 If 'options.select' contains a prefix of the error code,
611 return False. Else, if 'options.ignore' contains a prefix of
612 the error code, return True.
613 </p><a NAME="StyleGuide.init_report" ID="StyleGuide.init_report"></a>
614 <h4>StyleGuide.init_report</h4>
615 <b>init_report</b>(<i>reporter=None</i>)
616 <p>
617 Initialize the report instance.
618 </p><a NAME="StyleGuide.input_dir" ID="StyleGuide.input_dir"></a>
619 <h4>StyleGuide.input_dir</h4>
620 <b>input_dir</b>(<i>dirname</i>)
621 <p>
622 Check all files in this directory and all subdirectories.
623 </p><a NAME="StyleGuide.input_file" ID="StyleGuide.input_file"></a>
624 <h4>StyleGuide.input_file</h4>
625 <b>input_file</b>(<i>filename, lines=None, expected=None, line_offset=0</i>)
626 <p>
627 Run all checks on a Python source file.
628 </p>
629 <div align="right"><a href="#top">Up</a></div>
630 <hr /><hr />
631 <a NAME="_add_check" ID="_add_check"></a>
632 <h2>_add_check</h2>
633 <b>_add_check</b>(<i>check, kind, codes, args</i>)
634
635 <div align="right"><a href="#top">Up</a></div>
636 <hr /><hr />
637 <a NAME="_main" ID="_main"></a>
638 <h2>_main</h2>
639 <b>_main</b>(<i></i>)
640 <p>
641 Parse options and run checks on Python source.
642 </p>
643 <div align="right"><a href="#top">Up</a></div>
644 <hr /><hr />
645 <a NAME="blank_lines" ID="blank_lines"></a>
646 <h2>blank_lines</h2>
647 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level</i>)
648 <p>
649 Separate top-level function and class definitions with two blank lines.
650 </p><p>
651 Method definitions inside a class are separated by a single blank line.
652 </p><p>
653 Extra blank lines may be used (sparingly) to separate groups of related
654 functions. Blank lines may be omitted between a bunch of related
655 one-liners (e.g. a set of dummy implementations).
656 </p><p>
657 Use blank lines in functions, sparingly, to indicate logical sections.
658 </p><p>
659 Okay: def a():\n pass\n\n\ndef b():\n pass
660 Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass
661 </p><p>
662 E301: class Foo:\n b = 0\n def bar():\n pass
663 E302: def a():\n pass\n\ndef b(n):\n pass
664 E303: def a():\n pass\n\n\n\ndef b(n):\n pass
665 E303: def a():\n\n\n\n pass
666 E304: @decorator\n\ndef a():\n pass
667 </p>
668 <div align="right"><a href="#top">Up</a></div>
669 <hr /><hr />
670 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a>
671 <h2>comparison_to_singleton</h2>
672 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>)
673 <p>
674 Comparisons to singletons like None should always be done
675 with "is" or "is not", never the equality operators.
676 </p><p>
677 Okay: if arg is not None:
678 E711: if arg != None:
679 E712: if arg == True:
680 </p><p>
681 Also, beware of writing if x when you really mean if x is not None --
682 e.g. when testing whether a variable or argument that defaults to None was
683 set to some other value. The other value might have a type (such as a
684 container) that could be false in a boolean context!
685 </p>
686 <div align="right"><a href="#top">Up</a></div>
687 <hr /><hr />
688 <a NAME="comparison_type" ID="comparison_type"></a>
689 <h2>comparison_type</h2>
690 <b>comparison_type</b>(<i>logical_line</i>)
691 <p>
692 Object type comparisons should always use isinstance() instead of
693 comparing types directly.
694 </p><p>
695 Okay: if isinstance(obj, int):
696 E721: if type(obj) is type(1):
697 </p><p>
698 When checking if an object is a string, keep in mind that it might be a
699 unicode string too! In Python 2.3, str and unicode have a common base
700 class, basestring, so you can do:
701 </p><p>
702 Okay: if isinstance(obj, basestring):
703 Okay: if type(a1) is type(b1):
704 </p>
705 <div align="right"><a href="#top">Up</a></div>
706 <hr /><hr />
707 <a NAME="compound_statements" ID="compound_statements"></a>
708 <h2>compound_statements</h2>
709 <b>compound_statements</b>(<i>logical_line</i>)
710 <p>
711 Compound statements (multiple statements on the same line) are
712 generally discouraged.
713 </p><p>
714 While sometimes it's okay to put an if/for/while with a small body
715 on the same line, never do this for multi-clause statements. Also
716 avoid folding such long lines!
717 </p><p>
718 Okay: if foo == 'blah':\n do_blah_thing()
719 Okay: do_one()
720 Okay: do_two()
721 Okay: do_three()
722 </p><p>
723 E701: if foo == 'blah': do_blah_thing()
724 E701: for x in lst: total += x
725 E701: while t < 10: t = delay()
726 E701: if foo == 'blah': do_blah_thing()
727 E701: else: do_non_blah_thing()
728 E701: try: something()
729 E701: finally: cleanup()
730 E701: if foo == 'blah': one(); two(); three()
731 </p><p>
732 E702: do_one(); do_two(); do_three()
733 E703: do_four(); # useless semicolon
734 </p>
735 <div align="right"><a href="#top">Up</a></div>
736 <hr /><hr />
737 <a NAME="continued_indentation" ID="continued_indentation"></a>
738 <h2>continued_indentation</h2>
739 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, noqa, verbose</i>)
740 <p>
741 Continuation lines should align wrapped elements either vertically using
742 Python's implicit line joining inside parentheses, brackets and braces, or
743 using a hanging indent.
744 </p><p>
745 When using a hanging indent the following considerations should be applied:
746 </p><p>
747 - there should be no arguments on the first line, and
748 </p><p>
749 - further indentation should be used to clearly distinguish itself as a
750 continuation line.
751 </p><p>
752 Okay: a = (\n)
753 E123: a = (\n )
754 </p><p>
755 Okay: a = (\n 42)
756 E121: a = (\n 42)
757 E122: a = (\n42)
758 E123: a = (\n 42\n )
759 E124: a = (24,\n 42\n)
760 E125: if (a or\n b):\n pass
761 E126: a = (\n 42)
762 E127: a = (24,\n 42)
763 E128: a = (24,\n 42)
764 </p>
765 <div align="right"><a href="#top">Up</a></div>
766 <hr /><hr />
767 <a NAME="expand_indent" ID="expand_indent"></a>
768 <h2>expand_indent</h2>
769 <b>expand_indent</b>(<i>line</i>)
770 <p>
771 Return the amount of indentation.
772 Tabs are expanded to the next multiple of 8.
773 </p><p>
774 >>> expand_indent(' ')
775 4
776 >>> expand_indent('\t')
777 8
778 >>> expand_indent(' \t')
779 8
780 >>> expand_indent(' \t')
781 8
782 >>> expand_indent(' \t')
783 16
784 </p>
785 <div align="right"><a href="#top">Up</a></div>
786 <hr /><hr />
787 <a NAME="explicit_line_join" ID="explicit_line_join"></a>
788 <h2>explicit_line_join</h2>
789 <b>explicit_line_join</b>(<i>logical_line, tokens</i>)
790 <p>
791 Avoid explicit line join between brackets.
792 </p><p>
793 The preferred way of wrapping long lines is by using Python's implied line
794 continuation inside parentheses, brackets and braces. Long lines can be
795 broken over multiple lines by wrapping expressions in parentheses. These
796 should be used in preference to using a backslash for line continuation.
797 </p><p>
798 E502: aaa = [123, \\n 123]
799 E502: aaa = ("bbb " \\n "ccc")
800 </p><p>
801 Okay: aaa = [123,\n 123]
802 Okay: aaa = ("bbb "\n "ccc")
803 Okay: aaa = "bbb " \\n "ccc"
804 </p>
805 <div align="right"><a href="#top">Up</a></div>
806 <hr /><hr />
807 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a>
808 <h2>extraneous_whitespace</h2>
809 <b>extraneous_whitespace</b>(<i>logical_line</i>)
810 <p>
811 Avoid extraneous whitespace in the following situations:
812 </p><p>
813 - Immediately inside parentheses, brackets or braces.
814 </p><p>
815 - Immediately before a comma, semicolon, or colon.
816 </p><p>
817 Okay: spam(ham[1], {eggs: 2})
818 E201: spam( ham[1], {eggs: 2})
819 E201: spam(ham[ 1], {eggs: 2})
820 E201: spam(ham[1], { eggs: 2})
821 E202: spam(ham[1], {eggs: 2} )
822 E202: spam(ham[1 ], {eggs: 2})
823 E202: spam(ham[1], {eggs: 2 })
824 </p><p>
825 E203: if x == 4: print x, y; x, y = y , x
826 E203: if x == 4: print x, y ; x, y = y, x
827 E203: if x == 4 : print x, y; x, y = y, x
828 </p>
829 <div align="right"><a href="#top">Up</a></div>
830 <hr /><hr />
831 <a NAME="filename_match" ID="filename_match"></a>
832 <h2>filename_match</h2>
833 <b>filename_match</b>(<i>filename, patterns, default=True</i>)
834 <p>
835 Check if patterns contains a pattern that matches filename.
836 If patterns is unspecified, this always returns True.
837 </p>
838 <div align="right"><a href="#top">Up</a></div>
839 <hr /><hr />
840 <a NAME="get_parser" ID="get_parser"></a>
841 <h2>get_parser</h2>
842 <b>get_parser</b>(<i>prog='pep8', version=__version__</i>)
843
844 <div align="right"><a href="#top">Up</a></div>
845 <hr /><hr />
846 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a>
847 <h2>imports_on_separate_lines</h2>
848 <b>imports_on_separate_lines</b>(<i>logical_line</i>)
849 <p>
850 Imports should usually be on separate lines.
851 </p><p>
852 Okay: import os\nimport sys
853 E401: import sys, os
854 </p><p>
855 Okay: from subprocess import Popen, PIPE
856 Okay: from myclas import MyClass
857 Okay: from foo.bar.yourclass import YourClass
858 Okay: import myclass
859 Okay: import foo.bar.yourclass
860 </p>
861 <div align="right"><a href="#top">Up</a></div>
862 <hr /><hr />
863 <a NAME="indentation" ID="indentation"></a>
864 <h2>indentation</h2>
865 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>)
866 <p>
867 Use 4 spaces per indentation level.
868 </p><p>
869 For really old code that you don't want to mess up, you can continue to
870 use 8-space tabs.
871 </p><p>
872 Okay: a = 1
873 Okay: if a == 0:\n a = 1
874 E111: a = 1
875 </p><p>
876 Okay: for item in items:\n pass
877 E112: for item in items:\npass
878 </p><p>
879 Okay: a = 1\nb = 2
880 E113: a = 1\n b = 2
881 </p>
882 <div align="right"><a href="#top">Up</a></div>
883 <hr /><hr />
884 <a NAME="init_checks_registry" ID="init_checks_registry"></a>
885 <h2>init_checks_registry</h2>
886 <b>init_checks_registry</b>(<i></i>)
887 <p>
888 Register all globally visible functions where the first argument name
889 is 'physical_line' or 'logical_line'.
890 </p>
891 <div align="right"><a href="#top">Up</a></div>
892 <hr /><hr />
893 <a NAME="maximum_line_length" ID="maximum_line_length"></a>
894 <h2>maximum_line_length</h2>
895 <b>maximum_line_length</b>(<i>physical_line, max_line_length</i>)
896 <p>
897 Limit all lines to a maximum of 79 characters.
898 </p><p>
899 There are still many devices around that are limited to 80 character
900 lines; plus, limiting windows to 80 characters makes it possible to have
901 several windows side-by-side. The default wrapping on such devices looks
902 ugly. Therefore, please limit all lines to a maximum of 79 characters.
903 For flowing long blocks of text (docstrings or comments), limiting the
904 length to 72 characters is recommended.
905 </p><p>
906 Reports error E501.
907 </p>
908 <div align="right"><a href="#top">Up</a></div>
909 <hr /><hr />
910 <a NAME="missing_newline" ID="missing_newline"></a>
911 <h2>missing_newline</h2>
912 <b>missing_newline</b>(<i>physical_line</i>)
913 <p>
914 JCR: The last line should have a newline.
915 </p><p>
916 Reports warning W292.
917 </p>
918 <div align="right"><a href="#top">Up</a></div>
919 <hr /><hr />
920 <a NAME="missing_whitespace" ID="missing_whitespace"></a>
921 <h2>missing_whitespace</h2>
922 <b>missing_whitespace</b>(<i>logical_line</i>)
923 <p>
924 JCR: Each comma, semicolon or colon should be followed by whitespace.
925 </p><p>
926 Okay: [a, b]
927 Okay: (3,)
928 Okay: a[1:4]
929 Okay: a[:4]
930 Okay: a[1:]
931 Okay: a[1:4:2]
932 E231: ['a','b']
933 E231: foo(bar,baz)
934 E231: [{'a':'b'}]
935 </p>
936 <div align="right"><a href="#top">Up</a></div>
937 <hr /><hr />
938 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a>
939 <h2>missing_whitespace_around_operator</h2>
940 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>)
941 <p>
942 - Always surround these binary operators with a single space on
943 either side: assignment (=), augmented assignment (+=, -= etc.),
944 comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
945 Booleans (and, or, not).
946 </p><p>
947 - Use spaces around arithmetic operators.
948 </p><p>
949 Okay: i = i + 1
950 Okay: submitted += 1
951 Okay: x = x * 2 - 1
952 Okay: hypot2 = x * x + y * y
953 Okay: c = (a + b) * (a - b)
954 Okay: foo(bar, key='word', *args, **kwargs)
955 Okay: alpha[:-i]
956 </p><p>
957 E225: i=i+1
958 E225: submitted +=1
959 E225: x = x /2 - 1
960 E225: z = x **y
961 E226: c = (a+b) * (a-b)
962 E226: hypot2 = x*x + y*y
963 E227: c = a|b
964 E228: msg = fmt%(errno, errmsg)
965 </p>
966 <div align="right"><a href="#top">Up</a></div>
967 <hr /><hr />
968 <a NAME="mute_string" ID="mute_string"></a>
969 <h2>mute_string</h2>
970 <b>mute_string</b>(<i>text</i>)
971 <p>
972 Replace contents with 'xxx' to prevent syntax matching.
973 </p><p>
974 >>> mute_string('"abc"')
975 '"xxx"'
976 >>> mute_string("'''abc'''")
977 "'''xxx'''"
978 >>> mute_string("r'abc'")
979 "r'xxx'"
980 </p>
981 <div align="right"><a href="#top">Up</a></div>
982 <hr /><hr />
983 <a NAME="parse_udiff" ID="parse_udiff"></a>
984 <h2>parse_udiff</h2>
985 <b>parse_udiff</b>(<i>diff, patterns=None, parent='.'</i>)
986 <p>
987 Return a dictionary of matching lines.
988 </p>
989 <div align="right"><a href="#top">Up</a></div>
990 <hr /><hr />
991 <a NAME="process_options" ID="process_options"></a>
992 <h2>process_options</h2>
993 <b>process_options</b>(<i>arglist=None, parse_argv=False, config_file=None, parser=None</i>)
994 <p>
995 Process options passed either via arglist or via command line args.
996 </p>
997 <div align="right"><a href="#top">Up</a></div>
998 <hr /><hr />
999 <a NAME="python_3000_backticks" ID="python_3000_backticks"></a>
1000 <h2>python_3000_backticks</h2>
1001 <b>python_3000_backticks</b>(<i>logical_line</i>)
1002 <p>
1003 Backticks are removed in Python 3.
1004 Use repr() instead.
1005 </p><p>
1006 Okay: val = repr(1 + 2)
1007 W604: val = `1 + 2`
1008 </p>
1009 <div align="right"><a href="#top">Up</a></div>
1010 <hr /><hr />
1011 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a>
1012 <h2>python_3000_has_key</h2>
1013 <b>python_3000_has_key</b>(<i>logical_line</i>)
1014 <p>
1015 The {}.has_key() method is removed in the Python 3.
1016 Use the 'in' operation instead.
1017 </p><p>
1018 Okay: if "alph" in d:\n print d["alph"]
1019 W601: assert d.has_key('alph')
1020 </p>
1021 <div align="right"><a href="#top">Up</a></div>
1022 <hr /><hr />
1023 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a>
1024 <h2>python_3000_not_equal</h2>
1025 <b>python_3000_not_equal</b>(<i>logical_line</i>)
1026 <p>
1027 != can also be written <>, but this is an obsolete usage kept for
1028 backwards compatibility only. New code should always use !=.
1029 The older syntax is removed in Python 3.
1030 </p><p>
1031 Okay: if a != 'no':
1032 W603: if a <> 'no':
1033 </p>
1034 <div align="right"><a href="#top">Up</a></div>
1035 <hr /><hr />
1036 <a NAME="python_3000_raise_comma" ID="python_3000_raise_comma"></a>
1037 <h2>python_3000_raise_comma</h2>
1038 <b>python_3000_raise_comma</b>(<i>logical_line</i>)
1039 <p>
1040 When raising an exception, use "raise ValueError('message')"
1041 instead of the older form "raise ValueError, 'message'".
1042 </p><p>
1043 The paren-using form is preferred because when the exception arguments
1044 are long or include string formatting, you don't need to use line
1045 continuation characters thanks to the containing parentheses. The older
1046 form is removed in Python 3.
1047 </p><p>
1048 Okay: raise DummyError("Message")
1049 W602: raise DummyError, "Message"
1050 </p>
1051 <div align="right"><a href="#top">Up</a></div>
1052 <hr /><hr />
1053 <a NAME="read_config" ID="read_config"></a>
1054 <h2>read_config</h2>
1055 <b>read_config</b>(<i>options, args, arglist, parser</i>)
1056 <p>
1057 Read both user configuration and local configuration.
1058 </p>
1059 <div align="right"><a href="#top">Up</a></div>
1060 <hr /><hr />
1061 <a NAME="readlines" ID="readlines"></a>
1062 <h2>readlines</h2>
1063 <b>readlines</b>(<i>filename</i>)
1064
1065 <div align="right"><a href="#top">Up</a></div>
1066 <hr /><hr />
1067 <a NAME="readlines_1" ID="readlines_1"></a>
1068 <h2>readlines</h2>
1069 <b>readlines</b>(<i>filename</i>)
1070
1071 <div align="right"><a href="#top">Up</a></div>
1072 <hr /><hr />
1073 <a NAME="register_check" ID="register_check"></a>
1074 <h2>register_check</h2>
1075 <b>register_check</b>(<i>check, codes=None</i>)
1076 <p>
1077 Register a new check object.
1078 </p>
1079 <div align="right"><a href="#top">Up</a></div>
1080 <hr /><hr />
1081 <a NAME="stdin_get_value" ID="stdin_get_value"></a>
1082 <h2>stdin_get_value</h2>
1083 <b>stdin_get_value</b>(<i></i>)
1084
1085 <div align="right"><a href="#top">Up</a></div>
1086 <hr /><hr />
1087 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a>
1088 <h2>tabs_obsolete</h2>
1089 <b>tabs_obsolete</b>(<i>physical_line</i>)
1090 <p>
1091 For new projects, spaces-only are strongly recommended over tabs. Most
1092 editors have features that make this easy to do.
1093 </p><p>
1094 Okay: if True:\n return
1095 W191: if True:\n\treturn
1096 </p>
1097 <div align="right"><a href="#top">Up</a></div>
1098 <hr /><hr />
1099 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a>
1100 <h2>tabs_or_spaces</h2>
1101 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>)
1102 <p>
1103 Never mix tabs and spaces.
1104 </p><p>
1105 The most popular way of indenting Python is with spaces only. The
1106 second-most popular way is with tabs only. Code indented with a mixture
1107 of tabs and spaces should be converted to using spaces exclusively. When
1108 invoking the Python command line interpreter with the -t option, it issues
1109 warnings about code that illegally mixes tabs and spaces. When using -tt
1110 these warnings become errors. These options are highly recommended!
1111 </p><p>
1112 Okay: if a == 0:\n a = 1\n b = 1
1113 E101: if a == 0:\n a = 1\n\tb = 1
1114 </p>
1115 <div align="right"><a href="#top">Up</a></div>
1116 <hr /><hr />
1117 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a>
1118 <h2>trailing_blank_lines</h2>
1119 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>)
1120 <p>
1121 JCR: Trailing blank lines are superfluous.
1122 </p><p>
1123 Okay: spam(1)
1124 W391: spam(1)\n
1125 </p>
1126 <div align="right"><a href="#top">Up</a></div>
1127 <hr /><hr />
1128 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a>
1129 <h2>trailing_whitespace</h2>
1130 <b>trailing_whitespace</b>(<i>physical_line</i>)
1131 <p>
1132 JCR: Trailing whitespace is superfluous.
1133 FBM: Except when it occurs as part of a blank line (i.e. the line is
1134 nothing but whitespace). According to Python docs[1] a line with only
1135 whitespace is considered a blank line, and is to be ignored. However,
1136 matching a blank line to its indentation level avoids mistakenly
1137 terminating a multi-line statement (e.g. class declaration) when
1138 pasting code into the standard Python interpreter.
1139 </p><p>
1140 [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines
1141 </p><p>
1142 The warning returned varies on whether the line itself is blank, for easier
1143 filtering for those who want to indent their blank lines.
1144 </p><p>
1145 Okay: spam(1)\n#
1146 W291: spam(1) \n#
1147 W293: class Foo(object):\n \n bang = 12
1148 </p>
1149 <div align="right"><a href="#top">Up</a></div>
1150 <hr /><hr />
1151 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a>
1152 <h2>whitespace_around_comma</h2>
1153 <b>whitespace_around_comma</b>(<i>logical_line</i>)
1154 <p>
1155 Avoid extraneous whitespace in the following situations:
1156 </p><p>
1157 - More than one space around an assignment (or other) operator to
1158 align it with another.
1159 </p><p>
1160 JCR: This should also be applied around comma etc.
1161 Note: these checks are disabled by default
1162 </p><p>
1163 Okay: a = (1, 2)
1164 E241: a = (1, 2)
1165 E242: a = (1,\t2)
1166 </p>
1167 <div align="right"><a href="#top">Up</a></div>
1168 <hr /><hr />
1169 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a>
1170 <h2>whitespace_around_keywords</h2>
1171 <b>whitespace_around_keywords</b>(<i>logical_line</i>)
1172 <p>
1173 Avoid extraneous whitespace around keywords.
1174 </p><p>
1175 Okay: True and False
1176 E271: True and False
1177 E272: True and False
1178 E273: True and\tFalse
1179 E274: True\tand False
1180 </p>
1181 <div align="right"><a href="#top">Up</a></div>
1182 <hr /><hr />
1183 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a>
1184 <h2>whitespace_around_named_parameter_equals</h2>
1185 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>)
1186 <p>
1187 Don't use spaces around the '=' sign when used to indicate a
1188 keyword argument or a default parameter value.
1189 </p><p>
1190 Okay: def complex(real, imag=0.0):
1191 Okay: return magic(r=real, i=imag)
1192 Okay: boolean(a == b)
1193 Okay: boolean(a != b)
1194 Okay: boolean(a <= b)
1195 Okay: boolean(a >= b)
1196 </p><p>
1197 E251: def complex(real, imag = 0.0):
1198 E251: return magic(r = real, i = imag)
1199 </p>
1200 <div align="right"><a href="#top">Up</a></div>
1201 <hr /><hr />
1202 <a NAME="whitespace_around_operator" ID="whitespace_around_operator"></a>
1203 <h2>whitespace_around_operator</h2>
1204 <b>whitespace_around_operator</b>(<i>logical_line</i>)
1205 <p>
1206 Avoid extraneous whitespace in the following situations:
1207 </p><p>
1208 - More than one space around an assignment (or other) operator to
1209 align it with another.
1210 </p><p>
1211 Okay: a = 12 + 3
1212 E221: a = 4 + 5
1213 E222: a = 4 + 5
1214 E223: a = 4\t+ 5
1215 E224: a = 4 +\t5
1216 </p>
1217 <div align="right"><a href="#top">Up</a></div>
1218 <hr /><hr />
1219 <a NAME="whitespace_before_inline_comment" ID="whitespace_before_inline_comment"></a>
1220 <h2>whitespace_before_inline_comment</h2>
1221 <b>whitespace_before_inline_comment</b>(<i>logical_line, tokens</i>)
1222 <p>
1223 Separate inline comments by at least two spaces.
1224 </p><p>
1225 An inline comment is a comment on the same line as a statement. Inline
1226 comments should be separated by at least two spaces from the statement.
1227 They should start with a # and a single space.
1228 </p><p>
1229 Okay: x = x + 1 # Increment x
1230 Okay: x = x + 1 # Increment x
1231 E261: x = x + 1 # Increment x
1232 E262: x = x + 1 #Increment x
1233 E262: x = x + 1 # Increment x
1234 </p>
1235 <div align="right"><a href="#top">Up</a></div>
1236 <hr /><hr />
1237 <a NAME="whitespace_before_parameters" ID="whitespace_before_parameters"></a>
1238 <h2>whitespace_before_parameters</h2>
1239 <b>whitespace_before_parameters</b>(<i>logical_line, tokens</i>)
1240 <p>
1241 Avoid extraneous whitespace in the following situations:
1242 </p><p>
1243 - Immediately before the open parenthesis that starts the argument
1244 list of a function call.
1245 </p><p>
1246 - Immediately before the open parenthesis that starts an indexing or
1247 slicing.
1248 </p><p>
1249 Okay: spam(1)
1250 E211: spam (1)
1251 </p><p>
1252 Okay: dict['key'] = list[index]
1253 E211: dict ['key'] = list[index]
1254 E211: dict['key'] = list [index]
1255 </p>
1256 <div align="right"><a href="#top">Up</a></div>
1257 <hr />
1258 </body></html>

eric ide

mercurial