Documentation/Source/eric5.Plugins.CheckerPlugins.CodeStyleChecker.pep8.html

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

eric ide

mercurial