Documentation/Source/eric6.Plugins.CheckerPlugins.CodeStyleChecker.pycodestyle.html

changeset 5147
d39dd5cee0c8
child 5291
e93d14b48c34
equal deleted inserted replaced
5146:f96c32abd120 5147:d39dd5cee0c8
1 <!DOCTYPE html>
2 <html><head>
3 <title>eric6.Plugins.CheckerPlugins.CodeStyleChecker.pycodestyle</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>eric6.Plugins.CheckerPlugins.CodeStyleChecker.pycodestyle</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_NEGATIVE_REGEX</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>NEWLINE</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_COMMENTS</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="#_get_parameters">_get_parameters</a></td>
57 <td></td>
58 </tr><tr>
59 <td><a href="#_is_eol_token">_is_eol_token</a></td>
60 <td></td>
61 </tr><tr>
62 <td><a href="#_is_eol_token_1">_is_eol_token</a></td>
63 <td></td>
64 </tr><tr>
65 <td><a href="#_main">_main</a></td>
66 <td>Parse options and run checks on Python source.</td>
67 </tr><tr>
68 <td><a href="#_parse_multi_options">_parse_multi_options</a></td>
69 <td>Split and strip and discard empties.</td>
70 </tr><tr>
71 <td><a href="#ambiguous_identifier">ambiguous_identifier</a></td>
72 <td>Never use the characters 'l', 'O', or 'I' as variable names.</td>
73 </tr><tr>
74 <td><a href="#blank_lines">blank_lines</a></td>
75 <td>Separate top-level function and class definitions with two blank lines.</td>
76 </tr><tr>
77 <td><a href="#break_around_binary_operator">break_around_binary_operator</a></td>
78 <td>Avoid breaks before binary operators.</td>
79 </tr><tr>
80 <td><a href="#comparison_negative">comparison_negative</a></td>
81 <td>Negative comparison should be done using "not in" and "is not".</td>
82 </tr><tr>
83 <td><a href="#comparison_to_singleton">comparison_to_singleton</a></td>
84 <td>Comparison to singletons should use "is" or "is not".</td>
85 </tr><tr>
86 <td><a href="#comparison_type">comparison_type</a></td>
87 <td>Object type comparisons should always use isinstance().</td>
88 </tr><tr>
89 <td><a href="#compound_statements">compound_statements</a></td>
90 <td>Compound statements (on the same line) are generally discouraged.</td>
91 </tr><tr>
92 <td><a href="#continued_indentation">continued_indentation</a></td>
93 <td>Continuation lines indentation.</td>
94 </tr><tr>
95 <td><a href="#expand_indent">expand_indent</a></td>
96 <td>Return the amount of indentation.</td>
97 </tr><tr>
98 <td><a href="#explicit_line_join">explicit_line_join</a></td>
99 <td>Avoid explicit line join between brackets.</td>
100 </tr><tr>
101 <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td>
102 <td>Avoid extraneous whitespace.</td>
103 </tr><tr>
104 <td><a href="#filename_match">filename_match</a></td>
105 <td>Check if patterns contains a pattern that matches filename.</td>
106 </tr><tr>
107 <td><a href="#get_parser">get_parser</a></td>
108 <td>Create the parser for the program.</td>
109 </tr><tr>
110 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td>
111 <td>Place imports on separate lines.</td>
112 </tr><tr>
113 <td><a href="#indentation">indentation</a></td>
114 <td>Use 4 spaces per indentation level.</td>
115 </tr><tr>
116 <td><a href="#init_checks_registry">init_checks_registry</a></td>
117 <td>Register all globally visible functions.</td>
118 </tr><tr>
119 <td><a href="#is_binary_operator">is_binary_operator</a></td>
120 <td></td>
121 </tr><tr>
122 <td><a href="#is_string_literal">is_string_literal</a></td>
123 <td></td>
124 </tr><tr>
125 <td><a href="#maximum_line_length">maximum_line_length</a></td>
126 <td>Limit all lines to a maximum of 79 characters.</td>
127 </tr><tr>
128 <td><a href="#missing_whitespace">missing_whitespace</a></td>
129 <td>Each comma, semicolon or colon should be followed by whitespace.</td>
130 </tr><tr>
131 <td><a href="#missing_whitespace_after_import_keyword">missing_whitespace_after_import_keyword</a></td>
132 <td>Multiple imports in form from x import (a, b, c) should have space between import statement and parenthesised name list.</td>
133 </tr><tr>
134 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td>
135 <td>Surround operators with a single space on either side.</td>
136 </tr><tr>
137 <td><a href="#module_imports_on_top_of_file">module_imports_on_top_of_file</a></td>
138 <td>Place imports at the top of the file.</td>
139 </tr><tr>
140 <td><a href="#mute_string">mute_string</a></td>
141 <td>Replace contents with 'xxx' to prevent syntax matching.</td>
142 </tr><tr>
143 <td><a href="#normalize_paths">normalize_paths</a></td>
144 <td>Parse a comma-separated list of paths.</td>
145 </tr><tr>
146 <td><a href="#parse_udiff">parse_udiff</a></td>
147 <td>Return a dictionary of matching lines.</td>
148 </tr><tr>
149 <td><a href="#process_options">process_options</a></td>
150 <td>Process options passed either via arglist or via command line args.</td>
151 </tr><tr>
152 <td><a href="#python_3000_backticks">python_3000_backticks</a></td>
153 <td>Use repr() instead of backticks in Python 3.</td>
154 </tr><tr>
155 <td><a href="#python_3000_has_key">python_3000_has_key</a></td>
156 <td>The {}.has_key() method is removed in Python 3: use the 'in' operator.</td>
157 </tr><tr>
158 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td>
159 <td>New code should always use != instead of <>.</td>
160 </tr><tr>
161 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td>
162 <td>When raising an exception, use "raise ValueError('message')".</td>
163 </tr><tr>
164 <td><a href="#read_config">read_config</a></td>
165 <td>Read and parse configurations</td>
166 </tr><tr>
167 <td><a href="#readlines">readlines</a></td>
168 <td>Read the source code.</td>
169 </tr><tr>
170 <td><a href="#readlines_1">readlines</a></td>
171 <td>Read the source code.</td>
172 </tr><tr>
173 <td><a href="#register_check">register_check</a></td>
174 <td>Register a new check object.</td>
175 </tr><tr>
176 <td><a href="#stdin_get_value">stdin_get_value</a></td>
177 <td>Read the value from stdin.</td>
178 </tr><tr>
179 <td><a href="#tabs_obsolete">tabs_obsolete</a></td>
180 <td>For new projects, spaces-only are strongly recommended over tabs.</td>
181 </tr><tr>
182 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td>
183 <td>Never mix tabs and spaces.</td>
184 </tr><tr>
185 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td>
186 <td>Trailing blank lines are superfluous.</td>
187 </tr><tr>
188 <td><a href="#trailing_whitespace">trailing_whitespace</a></td>
189 <td>Trailing whitespace is superfluous.</td>
190 </tr><tr>
191 <td><a href="#update_counts">update_counts</a></td>
192 <td>Adds one to the counts of each appearance of characters in s, for characters in counts</td>
193 </tr><tr>
194 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td>
195 <td>Avoid extraneous whitespace after a comma or a colon.</td>
196 </tr><tr>
197 <td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td>
198 <td>Avoid extraneous whitespace around keywords.</td>
199 </tr><tr>
200 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td>
201 <td>Don't use spaces around the '=' sign in function arguments.</td>
202 </tr><tr>
203 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td>
204 <td>Avoid extraneous whitespace around an operator.</td>
205 </tr><tr>
206 <td><a href="#whitespace_before_comment">whitespace_before_comment</a></td>
207 <td>Separate inline comments by at least two spaces.</td>
208 </tr><tr>
209 <td><a href="#whitespace_before_parameters">whitespace_before_parameters</a></td>
210 <td>Avoid extraneous whitespace.</td>
211 </tr>
212 </table>
213 <hr /><hr />
214 <a NAME="BaseReport" ID="BaseReport"></a>
215 <h2>BaseReport</h2>
216 <p>
217 Collect the results of the checks.
218 </p>
219 <h3>Derived from</h3>
220 object
221 <h3>Class Attributes</h3>
222 <table>
223 <tr><td>print_filename</td></tr>
224 </table>
225 <h3>Class Methods</h3>
226 <table>
227 <tr><td>None</td></tr>
228 </table>
229 <h3>Methods</h3>
230 <table>
231 <tr>
232 <td><a href="#BaseReport.__init__">BaseReport</a></td>
233 <td></td>
234 </tr><tr>
235 <td><a href="#BaseReport.error">error</a></td>
236 <td>Report an error, according to options.</td>
237 </tr><tr>
238 <td><a href="#BaseReport.error_args">error_args</a></td>
239 <td>Report an error, according to options.</td>
240 </tr><tr>
241 <td><a href="#BaseReport.get_count">get_count</a></td>
242 <td>Return the total count of errors and warnings.</td>
243 </tr><tr>
244 <td><a href="#BaseReport.get_file_results">get_file_results</a></td>
245 <td>Return the count of errors and warnings for this file.</td>
246 </tr><tr>
247 <td><a href="#BaseReport.get_statistics">get_statistics</a></td>
248 <td>Get statistics for message codes that start with the prefix.</td>
249 </tr><tr>
250 <td><a href="#BaseReport.increment_logical_line">increment_logical_line</a></td>
251 <td>Signal a new logical line.</td>
252 </tr><tr>
253 <td><a href="#BaseReport.init_file">init_file</a></td>
254 <td>Signal a new file.</td>
255 </tr><tr>
256 <td><a href="#BaseReport.print_benchmark">print_benchmark</a></td>
257 <td>Print benchmark numbers.</td>
258 </tr><tr>
259 <td><a href="#BaseReport.print_statistics">print_statistics</a></td>
260 <td>Print overall statistics (number of errors and warnings).</td>
261 </tr><tr>
262 <td><a href="#BaseReport.start">start</a></td>
263 <td>Start the timer.</td>
264 </tr><tr>
265 <td><a href="#BaseReport.stop">stop</a></td>
266 <td>Stop the timer.</td>
267 </tr>
268 </table>
269 <h3>Static Methods</h3>
270 <table>
271 <tr><td>None</td></tr>
272 </table>
273 <a NAME="BaseReport.__init__" ID="BaseReport.__init__"></a>
274 <h4>BaseReport (Constructor)</h4>
275 <b>BaseReport</b>(<i>options</i>)
276 <a NAME="BaseReport.error" ID="BaseReport.error"></a>
277 <h4>BaseReport.error</h4>
278 <b>error</b>(<i>line_number, offset, text, check</i>)
279 <p>
280 Report an error, according to options.
281 </p><a NAME="BaseReport.error_args" ID="BaseReport.error_args"></a>
282 <h4>BaseReport.error_args</h4>
283 <b>error_args</b>(<i>line_number, offset, text, check, *args</i>)
284 <p>
285 Report an error, according to options.
286 </p><a NAME="BaseReport.get_count" ID="BaseReport.get_count"></a>
287 <h4>BaseReport.get_count</h4>
288 <b>get_count</b>(<i>prefix=''</i>)
289 <p>
290 Return the total count of errors and warnings.
291 </p><a NAME="BaseReport.get_file_results" ID="BaseReport.get_file_results"></a>
292 <h4>BaseReport.get_file_results</h4>
293 <b>get_file_results</b>(<i></i>)
294 <p>
295 Return the count of errors and warnings for this file.
296 </p><a NAME="BaseReport.get_statistics" ID="BaseReport.get_statistics"></a>
297 <h4>BaseReport.get_statistics</h4>
298 <b>get_statistics</b>(<i>prefix=''</i>)
299 <p>
300 Get statistics for message codes that start with the prefix.
301 </p><p>
302 prefix='' matches all errors and warnings
303 prefix='E' matches all errors
304 prefix='W' matches all warnings
305 prefix='E4' matches all errors that have to do with imports
306 </p><a NAME="BaseReport.increment_logical_line" ID="BaseReport.increment_logical_line"></a>
307 <h4>BaseReport.increment_logical_line</h4>
308 <b>increment_logical_line</b>(<i></i>)
309 <p>
310 Signal a new logical line.
311 </p><a NAME="BaseReport.init_file" ID="BaseReport.init_file"></a>
312 <h4>BaseReport.init_file</h4>
313 <b>init_file</b>(<i>filename, lines, expected, line_offset</i>)
314 <p>
315 Signal a new file.
316 </p><a NAME="BaseReport.print_benchmark" ID="BaseReport.print_benchmark"></a>
317 <h4>BaseReport.print_benchmark</h4>
318 <b>print_benchmark</b>(<i></i>)
319 <p>
320 Print benchmark numbers.
321 </p><a NAME="BaseReport.print_statistics" ID="BaseReport.print_statistics"></a>
322 <h4>BaseReport.print_statistics</h4>
323 <b>print_statistics</b>(<i>prefix=''</i>)
324 <p>
325 Print overall statistics (number of errors and warnings).
326 </p><a NAME="BaseReport.start" ID="BaseReport.start"></a>
327 <h4>BaseReport.start</h4>
328 <b>start</b>(<i></i>)
329 <p>
330 Start the timer.
331 </p><a NAME="BaseReport.stop" ID="BaseReport.stop"></a>
332 <h4>BaseReport.stop</h4>
333 <b>stop</b>(<i></i>)
334 <p>
335 Stop the timer.
336 </p>
337 <div align="right"><a href="#top">Up</a></div>
338 <hr /><hr />
339 <a NAME="Checker" ID="Checker"></a>
340 <h2>Checker</h2>
341 <p>
342 Load a Python source file, tokenize it, check coding style.
343 </p>
344 <h3>Derived from</h3>
345 object
346 <h3>Class Attributes</h3>
347 <table>
348 <tr><td>None</td></tr>
349 </table>
350 <h3>Class Methods</h3>
351 <table>
352 <tr><td>None</td></tr>
353 </table>
354 <h3>Methods</h3>
355 <table>
356 <tr>
357 <td><a href="#Checker.__init__">Checker</a></td>
358 <td></td>
359 </tr><tr>
360 <td><a href="#Checker.build_tokens_line">build_tokens_line</a></td>
361 <td>Build a logical line from tokens.</td>
362 </tr><tr>
363 <td><a href="#Checker.check_all">check_all</a></td>
364 <td>Run all checks on the input file.</td>
365 </tr><tr>
366 <td><a href="#Checker.check_ast">check_ast</a></td>
367 <td>Build the file's AST and run all AST checks.</td>
368 </tr><tr>
369 <td><a href="#Checker.check_logical">check_logical</a></td>
370 <td>Build a line from tokens and run all logical checks on it.</td>
371 </tr><tr>
372 <td><a href="#Checker.check_physical">check_physical</a></td>
373 <td>Run all physical checks on a raw input line.</td>
374 </tr><tr>
375 <td><a href="#Checker.generate_tokens">generate_tokens</a></td>
376 <td>Tokenize the file, run physical line checks and yield tokens.</td>
377 </tr><tr>
378 <td><a href="#Checker.init_checker_state">init_checker_state</a></td>
379 <td>Prepare custom state for the specific checker plugin.</td>
380 </tr><tr>
381 <td><a href="#Checker.maybe_check_physical">maybe_check_physical</a></td>
382 <td>If appropriate (based on token), check current physical line(s).</td>
383 </tr><tr>
384 <td><a href="#Checker.readline">readline</a></td>
385 <td>Get the next line from the input buffer.</td>
386 </tr><tr>
387 <td><a href="#Checker.report_invalid_syntax">report_invalid_syntax</a></td>
388 <td>Check if the syntax is valid.</td>
389 </tr><tr>
390 <td><a href="#Checker.run_check">run_check</a></td>
391 <td>Run a check plugin.</td>
392 </tr>
393 </table>
394 <h3>Static Methods</h3>
395 <table>
396 <tr><td>None</td></tr>
397 </table>
398 <a NAME="Checker.__init__" ID="Checker.__init__"></a>
399 <h4>Checker (Constructor)</h4>
400 <b>Checker</b>(<i>filename=None, lines=None, options=None, report=None, **kwargs</i>)
401 <a NAME="Checker.build_tokens_line" ID="Checker.build_tokens_line"></a>
402 <h4>Checker.build_tokens_line</h4>
403 <b>build_tokens_line</b>(<i></i>)
404 <p>
405 Build a logical line from tokens.
406 </p><a NAME="Checker.check_all" ID="Checker.check_all"></a>
407 <h4>Checker.check_all</h4>
408 <b>check_all</b>(<i>expected=None, line_offset=0</i>)
409 <p>
410 Run all checks on the input file.
411 </p><a NAME="Checker.check_ast" ID="Checker.check_ast"></a>
412 <h4>Checker.check_ast</h4>
413 <b>check_ast</b>(<i></i>)
414 <p>
415 Build the file's AST and run all AST checks.
416 </p><a NAME="Checker.check_logical" ID="Checker.check_logical"></a>
417 <h4>Checker.check_logical</h4>
418 <b>check_logical</b>(<i></i>)
419 <p>
420 Build a line from tokens and run all logical checks on it.
421 </p><a NAME="Checker.check_physical" ID="Checker.check_physical"></a>
422 <h4>Checker.check_physical</h4>
423 <b>check_physical</b>(<i>line</i>)
424 <p>
425 Run all physical checks on a raw input line.
426 </p><a NAME="Checker.generate_tokens" ID="Checker.generate_tokens"></a>
427 <h4>Checker.generate_tokens</h4>
428 <b>generate_tokens</b>(<i></i>)
429 <p>
430 Tokenize the file, run physical line checks and yield tokens.
431 </p><a NAME="Checker.init_checker_state" ID="Checker.init_checker_state"></a>
432 <h4>Checker.init_checker_state</h4>
433 <b>init_checker_state</b>(<i>name, argument_names</i>)
434 <p>
435 Prepare custom state for the specific checker plugin.
436 </p><a NAME="Checker.maybe_check_physical" ID="Checker.maybe_check_physical"></a>
437 <h4>Checker.maybe_check_physical</h4>
438 <b>maybe_check_physical</b>(<i>token</i>)
439 <p>
440 If appropriate (based on token), check current physical line(s).
441 </p><a NAME="Checker.readline" ID="Checker.readline"></a>
442 <h4>Checker.readline</h4>
443 <b>readline</b>(<i></i>)
444 <p>
445 Get the next line from the input buffer.
446 </p><a NAME="Checker.report_invalid_syntax" ID="Checker.report_invalid_syntax"></a>
447 <h4>Checker.report_invalid_syntax</h4>
448 <b>report_invalid_syntax</b>(<i></i>)
449 <p>
450 Check if the syntax is valid.
451 </p><a NAME="Checker.run_check" ID="Checker.run_check"></a>
452 <h4>Checker.run_check</h4>
453 <b>run_check</b>(<i>check, argument_names</i>)
454 <p>
455 Run a check plugin.
456 </p>
457 <div align="right"><a href="#top">Up</a></div>
458 <hr /><hr />
459 <a NAME="DiffReport" ID="DiffReport"></a>
460 <h2>DiffReport</h2>
461 <p>
462 Collect and print the results for the changed lines only.
463 </p>
464 <h3>Derived from</h3>
465 StandardReport
466 <h3>Class Attributes</h3>
467 <table>
468 <tr><td>None</td></tr>
469 </table>
470 <h3>Class Methods</h3>
471 <table>
472 <tr><td>None</td></tr>
473 </table>
474 <h3>Methods</h3>
475 <table>
476 <tr>
477 <td><a href="#DiffReport.__init__">DiffReport</a></td>
478 <td></td>
479 </tr><tr>
480 <td><a href="#DiffReport.error">error</a></td>
481 <td></td>
482 </tr>
483 </table>
484 <h3>Static Methods</h3>
485 <table>
486 <tr><td>None</td></tr>
487 </table>
488 <a NAME="DiffReport.__init__" ID="DiffReport.__init__"></a>
489 <h4>DiffReport (Constructor)</h4>
490 <b>DiffReport</b>(<i>options</i>)
491 <a NAME="DiffReport.error" ID="DiffReport.error"></a>
492 <h4>DiffReport.error</h4>
493 <b>error</b>(<i>line_number, offset, text, check</i>)
494
495 <div align="right"><a href="#top">Up</a></div>
496 <hr /><hr />
497 <a NAME="FileReport" ID="FileReport"></a>
498 <h2>FileReport</h2>
499 <p>
500 Collect the results of the checks and print only the filenames.
501 </p>
502 <h3>Derived from</h3>
503 BaseReport
504 <h3>Class Attributes</h3>
505 <table>
506 <tr><td>print_filename</td></tr>
507 </table>
508 <h3>Class Methods</h3>
509 <table>
510 <tr><td>None</td></tr>
511 </table>
512 <h3>Methods</h3>
513 <table>
514 <tr><td>None</td></tr>
515 </table>
516 <h3>Static Methods</h3>
517 <table>
518 <tr><td>None</td></tr>
519 </table>
520
521 <div align="right"><a href="#top">Up</a></div>
522 <hr /><hr />
523 <a NAME="StandardReport" ID="StandardReport"></a>
524 <h2>StandardReport</h2>
525 <p>
526 Collect and print the results of the checks.
527 </p>
528 <h3>Derived from</h3>
529 BaseReport
530 <h3>Class Attributes</h3>
531 <table>
532 <tr><td>None</td></tr>
533 </table>
534 <h3>Class Methods</h3>
535 <table>
536 <tr><td>None</td></tr>
537 </table>
538 <h3>Methods</h3>
539 <table>
540 <tr>
541 <td><a href="#StandardReport.__init__">StandardReport</a></td>
542 <td></td>
543 </tr><tr>
544 <td><a href="#StandardReport.error">error</a></td>
545 <td>Report an error, according to options.</td>
546 </tr><tr>
547 <td><a href="#StandardReport.error_args">error_args</a></td>
548 <td>Report an error, according to options.</td>
549 </tr><tr>
550 <td><a href="#StandardReport.get_file_results">get_file_results</a></td>
551 <td>Print the result and return the overall count for this file.</td>
552 </tr><tr>
553 <td><a href="#StandardReport.init_file">init_file</a></td>
554 <td>Signal a new file.</td>
555 </tr>
556 </table>
557 <h3>Static Methods</h3>
558 <table>
559 <tr><td>None</td></tr>
560 </table>
561 <a NAME="StandardReport.__init__" ID="StandardReport.__init__"></a>
562 <h4>StandardReport (Constructor)</h4>
563 <b>StandardReport</b>(<i>options</i>)
564 <a NAME="StandardReport.error" ID="StandardReport.error"></a>
565 <h4>StandardReport.error</h4>
566 <b>error</b>(<i>line_number, offset, text, check</i>)
567 <p>
568 Report an error, according to options.
569 </p><a NAME="StandardReport.error_args" ID="StandardReport.error_args"></a>
570 <h4>StandardReport.error_args</h4>
571 <b>error_args</b>(<i>line_number, offset, code, check, *args</i>)
572 <p>
573 Report an error, according to options.
574 </p><a NAME="StandardReport.get_file_results" ID="StandardReport.get_file_results"></a>
575 <h4>StandardReport.get_file_results</h4>
576 <b>get_file_results</b>(<i></i>)
577 <p>
578 Print the result and return the overall count for this file.
579 </p><a NAME="StandardReport.init_file" ID="StandardReport.init_file"></a>
580 <h4>StandardReport.init_file</h4>
581 <b>init_file</b>(<i>filename, lines, expected, line_offset</i>)
582 <p>
583 Signal a new file.
584 </p>
585 <div align="right"><a href="#top">Up</a></div>
586 <hr /><hr />
587 <a NAME="StyleGuide" ID="StyleGuide"></a>
588 <h2>StyleGuide</h2>
589 <p>
590 Initialize a PEP-8 instance with few options.
591 </p>
592 <h3>Derived from</h3>
593 object
594 <h3>Class Attributes</h3>
595 <table>
596 <tr><td>None</td></tr>
597 </table>
598 <h3>Class Methods</h3>
599 <table>
600 <tr><td>None</td></tr>
601 </table>
602 <h3>Methods</h3>
603 <table>
604 <tr>
605 <td><a href="#StyleGuide.__init__">StyleGuide</a></td>
606 <td></td>
607 </tr><tr>
608 <td><a href="#StyleGuide.check_files">check_files</a></td>
609 <td>Run all checks on the paths.</td>
610 </tr><tr>
611 <td><a href="#StyleGuide.excluded">excluded</a></td>
612 <td>Check if the file should be excluded.</td>
613 </tr><tr>
614 <td><a href="#StyleGuide.get_checks">get_checks</a></td>
615 <td>Get all the checks for this category.</td>
616 </tr><tr>
617 <td><a href="#StyleGuide.ignore_code">ignore_code</a></td>
618 <td>Check if the error code should be ignored.</td>
619 </tr><tr>
620 <td><a href="#StyleGuide.init_report">init_report</a></td>
621 <td>Initialize the report instance.</td>
622 </tr><tr>
623 <td><a href="#StyleGuide.input_dir">input_dir</a></td>
624 <td>Check all files in this directory and all subdirectories.</td>
625 </tr><tr>
626 <td><a href="#StyleGuide.input_file">input_file</a></td>
627 <td>Run all checks on a Python source file.</td>
628 </tr>
629 </table>
630 <h3>Static Methods</h3>
631 <table>
632 <tr><td>None</td></tr>
633 </table>
634 <a NAME="StyleGuide.__init__" ID="StyleGuide.__init__"></a>
635 <h4>StyleGuide (Constructor)</h4>
636 <b>StyleGuide</b>(<i>*args, **kwargs</i>)
637 <a NAME="StyleGuide.check_files" ID="StyleGuide.check_files"></a>
638 <h4>StyleGuide.check_files</h4>
639 <b>check_files</b>(<i>paths=None</i>)
640 <p>
641 Run all checks on the paths.
642 </p><a NAME="StyleGuide.excluded" ID="StyleGuide.excluded"></a>
643 <h4>StyleGuide.excluded</h4>
644 <b>excluded</b>(<i>filename, parent=None</i>)
645 <p>
646 Check if the file should be excluded.
647 </p><p>
648 Check if 'options.exclude' contains a pattern that matches filename.
649 </p><a NAME="StyleGuide.get_checks" ID="StyleGuide.get_checks"></a>
650 <h4>StyleGuide.get_checks</h4>
651 <b>get_checks</b>(<i>argument_name</i>)
652 <p>
653 Get all the checks for this category.
654 </p><p>
655 Find all globally visible functions where the first argument name
656 starts with argument_name and which contain selected tests.
657 </p><a NAME="StyleGuide.ignore_code" ID="StyleGuide.ignore_code"></a>
658 <h4>StyleGuide.ignore_code</h4>
659 <b>ignore_code</b>(<i>code</i>)
660 <p>
661 Check if the error code should be ignored.
662 </p><p>
663 If 'options.select' contains a prefix of the error code,
664 return False. Else, if 'options.ignore' contains a prefix of
665 the error code, return True.
666 </p><a NAME="StyleGuide.init_report" ID="StyleGuide.init_report"></a>
667 <h4>StyleGuide.init_report</h4>
668 <b>init_report</b>(<i>reporter=None</i>)
669 <p>
670 Initialize the report instance.
671 </p><a NAME="StyleGuide.input_dir" ID="StyleGuide.input_dir"></a>
672 <h4>StyleGuide.input_dir</h4>
673 <b>input_dir</b>(<i>dirname</i>)
674 <p>
675 Check all files in this directory and all subdirectories.
676 </p><a NAME="StyleGuide.input_file" ID="StyleGuide.input_file"></a>
677 <h4>StyleGuide.input_file</h4>
678 <b>input_file</b>(<i>filename, lines=None, expected=None, line_offset=0</i>)
679 <p>
680 Run all checks on a Python source file.
681 </p>
682 <div align="right"><a href="#top">Up</a></div>
683 <hr /><hr />
684 <a NAME="_add_check" ID="_add_check"></a>
685 <h2>_add_check</h2>
686 <b>_add_check</b>(<i>check, kind, codes, args</i>)
687
688 <div align="right"><a href="#top">Up</a></div>
689 <hr /><hr />
690 <a NAME="_get_parameters" ID="_get_parameters"></a>
691 <h2>_get_parameters</h2>
692 <b>_get_parameters</b>(<i>function</i>)
693
694 <div align="right"><a href="#top">Up</a></div>
695 <hr /><hr />
696 <a NAME="_is_eol_token" ID="_is_eol_token"></a>
697 <h2>_is_eol_token</h2>
698 <b>_is_eol_token</b>(<i>token</i>)
699
700 <div align="right"><a href="#top">Up</a></div>
701 <hr /><hr />
702 <a NAME="_is_eol_token_1" ID="_is_eol_token_1"></a>
703 <h2>_is_eol_token</h2>
704 <b>_is_eol_token</b>(<i>token, _eol_token=_is_eol_token</i>)
705
706 <div align="right"><a href="#top">Up</a></div>
707 <hr /><hr />
708 <a NAME="_main" ID="_main"></a>
709 <h2>_main</h2>
710 <b>_main</b>(<i></i>)
711 <p>
712 Parse options and run checks on Python source.
713 </p>
714 <div align="right"><a href="#top">Up</a></div>
715 <hr /><hr />
716 <a NAME="_parse_multi_options" ID="_parse_multi_options"></a>
717 <h2>_parse_multi_options</h2>
718 <b>_parse_multi_options</b>(<i>options, split_token=', '</i>)
719 <p>
720 Split and strip and discard empties.
721 </p><p>
722 Turns the following:
723 </p><p>
724 A,
725 B,
726 </p><p>
727 into ["A", "B"]
728 </p>
729 <div align="right"><a href="#top">Up</a></div>
730 <hr /><hr />
731 <a NAME="ambiguous_identifier" ID="ambiguous_identifier"></a>
732 <h2>ambiguous_identifier</h2>
733 <b>ambiguous_identifier</b>(<i>logical_line, tokens</i>)
734 <p>
735 Never use the characters 'l', 'O', or 'I' as variable names.
736 </p><p>
737 In some fonts, these characters are indistinguishable from the numerals
738 one and zero. When tempted to use 'l', use 'L' instead.
739 </p><p>
740 Okay: L = 0
741 Okay: o = 123
742 Okay: i = 42
743 E741: l = 0
744 E741: O = 123
745 E741: I = 42
746 </p><p>
747 Variables can be bound in several other contexts, including class and
748 function definitions, 'global' and 'nonlocal' statements, exception
749 handlers, and 'with' statements.
750 </p><p>
751 Okay: except AttributeError as o:
752 Okay: with lock as L:
753 E741: except AttributeError as O:
754 E741: with lock as l:
755 E741: global I
756 E741: nonlocal l
757 E742: class I(object):
758 E743: def l(x):
759 </p>
760 <div align="right"><a href="#top">Up</a></div>
761 <hr /><hr />
762 <a NAME="blank_lines" ID="blank_lines"></a>
763 <h2>blank_lines</h2>
764 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, blank_before, previous_logical, previous_unindented_logical_line, previous_indent_level, lines</i>)
765 <p>
766 Separate top-level function and class definitions with two blank lines.
767 </p><p>
768 Method definitions inside a class are separated by a single blank line.
769 </p><p>
770 Extra blank lines may be used (sparingly) to separate groups of related
771 functions. Blank lines may be omitted between a bunch of related
772 one-liners (e.g. a set of dummy implementations).
773 </p><p>
774 Use blank lines in functions, sparingly, to indicate logical sections.
775 </p><p>
776 Okay: def a():\n pass\n\n\ndef b():\n pass
777 Okay: def a():\n pass\n\n\nasync def b():\n pass
778 Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass
779 </p><p>
780 E301: class Foo:\n b = 0\n def bar():\n pass
781 E302: def a():\n pass\n\ndef b(n):\n pass
782 E302: def a():\n pass\n\nasync def b(n):\n pass
783 E303: def a():\n pass\n\n\n\ndef b(n):\n pass
784 E303: def a():\n\n\n\n pass
785 E304: @decorator\n\ndef a():\n pass
786 E305: def a():\n pass\na()
787 </p>
788 <div align="right"><a href="#top">Up</a></div>
789 <hr /><hr />
790 <a NAME="break_around_binary_operator" ID="break_around_binary_operator"></a>
791 <h2>break_around_binary_operator</h2>
792 <b>break_around_binary_operator</b>(<i>logical_line, tokens</i>)
793 <p>
794 Avoid breaks before binary operators.
795 </p><p>
796 The preferred place to break around a binary operator is after the
797 operator, not before it.
798 </p><p>
799 W503: (width == 0\n + height == 0)
800 W503: (width == 0\n and height == 0)
801 </p><p>
802 Okay: (width == 0 +\n height == 0)
803 Okay: foo(\n -x)
804 Okay: foo(x\n [])
805 Okay: x = '''\n''' + ''
806 Okay: foo(x,\n -y)
807 Okay: foo(x, # comment\n -y)
808 Okay: var = (1 &\n ~2)
809 Okay: var = (1 /\n -2)
810 Okay: var = (1 +\n -1 +\n -2)
811 </p>
812 <div align="right"><a href="#top">Up</a></div>
813 <hr /><hr />
814 <a NAME="comparison_negative" ID="comparison_negative"></a>
815 <h2>comparison_negative</h2>
816 <b>comparison_negative</b>(<i>logical_line</i>)
817 <p>
818 Negative comparison should be done using "not in" and "is not".
819 </p><p>
820 Okay: if x not in y:\n pass
821 Okay: assert (X in Y or X is Z)
822 Okay: if not (X in Y):\n pass
823 Okay: zz = x is not y
824 E713: Z = not X in Y
825 E713: if not X.B in Y:\n pass
826 E714: if not X is Y:\n pass
827 E714: Z = not X.B is Y
828 </p>
829 <div align="right"><a href="#top">Up</a></div>
830 <hr /><hr />
831 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a>
832 <h2>comparison_to_singleton</h2>
833 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>)
834 <p>
835 Comparison to singletons should use "is" or "is not".
836 </p><p>
837 Comparisons to singletons like None should always be done
838 with "is" or "is not", never the equality operators.
839 </p><p>
840 Okay: if arg is not None:
841 E711: if arg != None:
842 E711: if None == arg:
843 E712: if arg == True:
844 E712: if False == arg:
845 </p><p>
846 Also, beware of writing if x when you really mean if x is not None --
847 e.g. when testing whether a variable or argument that defaults to None was
848 set to some other value. The other value might have a type (such as a
849 container) that could be false in a boolean context!
850 </p>
851 <div align="right"><a href="#top">Up</a></div>
852 <hr /><hr />
853 <a NAME="comparison_type" ID="comparison_type"></a>
854 <h2>comparison_type</h2>
855 <b>comparison_type</b>(<i>logical_line, noqa</i>)
856 <p>
857 Object type comparisons should always use isinstance().
858 </p><p>
859 Do not compare types directly.
860 </p><p>
861 Okay: if isinstance(obj, int):
862 E721: if type(obj) is type(1):
863 </p><p>
864 When checking if an object is a string, keep in mind that it might be a
865 unicode string too! In Python 2.3, str and unicode have a common base
866 class, basestring, so you can do:
867 </p><p>
868 Okay: if isinstance(obj, basestring):
869 Okay: if type(a1) is type(b1):
870 </p>
871 <div align="right"><a href="#top">Up</a></div>
872 <hr /><hr />
873 <a NAME="compound_statements" ID="compound_statements"></a>
874 <h2>compound_statements</h2>
875 <b>compound_statements</b>(<i>logical_line</i>)
876 <p>
877 Compound statements (on the same line) are generally discouraged.
878 </p><p>
879 While sometimes it's okay to put an if/for/while with a small body
880 on the same line, never do this for multi-clause statements.
881 Also avoid folding such long lines!
882 </p><p>
883 Always use a def statement instead of an assignment statement that
884 binds a lambda expression directly to a name.
885 </p><p>
886 Okay: if foo == 'blah':\n do_blah_thing()
887 Okay: do_one()
888 Okay: do_two()
889 Okay: do_three()
890 </p><p>
891 E701: if foo == 'blah': do_blah_thing()
892 E701: for x in lst: total += x
893 E701: while t < 10: t = delay()
894 E701: if foo == 'blah': do_blah_thing()
895 E701: else: do_non_blah_thing()
896 E701: try: something()
897 E701: finally: cleanup()
898 E701: if foo == 'blah': one(); two(); three()
899 E702: do_one(); do_two(); do_three()
900 E703: do_four(); # useless semicolon
901 E704: def f(x): return 2*x
902 E705: async def f(x): return 2*x
903 E731: f = lambda x: 2*x
904 </p>
905 <div align="right"><a href="#top">Up</a></div>
906 <hr /><hr />
907 <a NAME="continued_indentation" ID="continued_indentation"></a>
908 <h2>continued_indentation</h2>
909 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, indent_char, noqa, verbose</i>)
910 <p>
911 Continuation lines indentation.
912 </p><p>
913 Continuation lines should align wrapped elements either vertically
914 using Python's implicit line joining inside parentheses, brackets
915 and braces, or using a hanging indent.
916 </p><p>
917 When using a hanging indent these considerations should be applied:
918 - there should be no arguments on the first line, and
919 - further indentation should be used to clearly distinguish itself as a
920 continuation line.
921 </p><p>
922 Okay: a = (\n)
923 E123: a = (\n )
924 </p><p>
925 Okay: a = (\n 42)
926 E121: a = (\n 42)
927 E122: a = (\n42)
928 E123: a = (\n 42\n )
929 E124: a = (24,\n 42\n)
930 E125: if (\n b):\n pass
931 E126: a = (\n 42)
932 E127: a = (24,\n 42)
933 E128: a = (24,\n 42)
934 E129: if (a or\n b):\n pass
935 E131: a = (\n 42\n 24)
936 </p>
937 <div align="right"><a href="#top">Up</a></div>
938 <hr /><hr />
939 <a NAME="expand_indent" ID="expand_indent"></a>
940 <h2>expand_indent</h2>
941 <b>expand_indent</b>(<i>line</i>)
942 <p>
943 Return the amount of indentation.
944 </p><p>
945 Tabs are expanded to the next multiple of 8.
946 </p><p>
947 >>> expand_indent(' ')
948 4
949 >>> expand_indent('\t')
950 8
951 >>> expand_indent(' \t')
952 8
953 >>> expand_indent(' \t')
954 16
955 </p>
956 <div align="right"><a href="#top">Up</a></div>
957 <hr /><hr />
958 <a NAME="explicit_line_join" ID="explicit_line_join"></a>
959 <h2>explicit_line_join</h2>
960 <b>explicit_line_join</b>(<i>logical_line, tokens</i>)
961 <p>
962 Avoid explicit line join between brackets.
963 </p><p>
964 The preferred way of wrapping long lines is by using Python's implied line
965 continuation inside parentheses, brackets and braces. Long lines can be
966 broken over multiple lines by wrapping expressions in parentheses. These
967 should be used in preference to using a backslash for line continuation.
968 </p><p>
969 E502: aaa = [123, \\n 123]
970 E502: aaa = ("bbb " \\n "ccc")
971 </p><p>
972 Okay: aaa = [123,\n 123]
973 Okay: aaa = ("bbb "\n "ccc")
974 Okay: aaa = "bbb " \\n "ccc"
975 Okay: aaa = 123 # \\
976 </p>
977 <div align="right"><a href="#top">Up</a></div>
978 <hr /><hr />
979 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a>
980 <h2>extraneous_whitespace</h2>
981 <b>extraneous_whitespace</b>(<i>logical_line</i>)
982 <p>
983 Avoid extraneous whitespace.
984 </p><p>
985 Avoid extraneous whitespace in these situations:
986 - Immediately inside parentheses, brackets or braces.
987 - Immediately before a comma, semicolon, or colon.
988 </p><p>
989 Okay: spam(ham[1], {eggs: 2})
990 E201: spam( ham[1], {eggs: 2})
991 E201: spam(ham[ 1], {eggs: 2})
992 E201: spam(ham[1], { eggs: 2})
993 E202: spam(ham[1], {eggs: 2} )
994 E202: spam(ham[1 ], {eggs: 2})
995 E202: spam(ham[1], {eggs: 2 })
996 </p><p>
997 E203: if x == 4: print x, y; x, y = y , x
998 E203: if x == 4: print x, y ; x, y = y, x
999 E203: if x == 4 : print x, y; x, y = y, x
1000 </p>
1001 <div align="right"><a href="#top">Up</a></div>
1002 <hr /><hr />
1003 <a NAME="filename_match" ID="filename_match"></a>
1004 <h2>filename_match</h2>
1005 <b>filename_match</b>(<i>filename, patterns, default=True</i>)
1006 <p>
1007 Check if patterns contains a pattern that matches filename.
1008 </p><p>
1009 If patterns is unspecified, this always returns True.
1010 </p>
1011 <div align="right"><a href="#top">Up</a></div>
1012 <hr /><hr />
1013 <a NAME="get_parser" ID="get_parser"></a>
1014 <h2>get_parser</h2>
1015 <b>get_parser</b>(<i>prog='pycodestyle', version=__version__</i>)
1016 <p>
1017 Create the parser for the program.
1018 </p>
1019 <div align="right"><a href="#top">Up</a></div>
1020 <hr /><hr />
1021 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a>
1022 <h2>imports_on_separate_lines</h2>
1023 <b>imports_on_separate_lines</b>(<i>logical_line</i>)
1024 <p>
1025 Place imports on separate lines.
1026 </p><p>
1027 Okay: import os\nimport sys
1028 E401: import sys, os
1029 </p><p>
1030 Okay: from subprocess import Popen, PIPE
1031 Okay: from myclas import MyClass
1032 Okay: from foo.bar.yourclass import YourClass
1033 Okay: import myclass
1034 Okay: import foo.bar.yourclass
1035 </p>
1036 <div align="right"><a href="#top">Up</a></div>
1037 <hr /><hr />
1038 <a NAME="indentation" ID="indentation"></a>
1039 <h2>indentation</h2>
1040 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>)
1041 <p>
1042 Use 4 spaces per indentation level.
1043 </p><p>
1044 For really old code that you don't want to mess up, you can continue to
1045 use 8-space tabs.
1046 </p><p>
1047 Okay: a = 1
1048 Okay: if a == 0:\n a = 1
1049 E111: a = 1
1050 E114: # a = 1
1051 </p><p>
1052 Okay: for item in items:\n pass
1053 E112: for item in items:\npass
1054 E115: for item in items:\n# Hi\n pass
1055 </p><p>
1056 Okay: a = 1\nb = 2
1057 E113: a = 1\n b = 2
1058 E116: a = 1\n # b = 2
1059 </p>
1060 <div align="right"><a href="#top">Up</a></div>
1061 <hr /><hr />
1062 <a NAME="init_checks_registry" ID="init_checks_registry"></a>
1063 <h2>init_checks_registry</h2>
1064 <b>init_checks_registry</b>(<i></i>)
1065 <p>
1066 Register all globally visible functions.
1067 </p><p>
1068 The first argument name is either 'physical_line' or 'logical_line'.
1069 </p>
1070 <div align="right"><a href="#top">Up</a></div>
1071 <hr /><hr />
1072 <a NAME="is_binary_operator" ID="is_binary_operator"></a>
1073 <h2>is_binary_operator</h2>
1074 <b>is_binary_operator</b>(<i>token_type, text</i>)
1075
1076 <div align="right"><a href="#top">Up</a></div>
1077 <hr /><hr />
1078 <a NAME="is_string_literal" ID="is_string_literal"></a>
1079 <h2>is_string_literal</h2>
1080 <b>is_string_literal</b>(<i>line</i>)
1081
1082 <div align="right"><a href="#top">Up</a></div>
1083 <hr /><hr />
1084 <a NAME="maximum_line_length" ID="maximum_line_length"></a>
1085 <h2>maximum_line_length</h2>
1086 <b>maximum_line_length</b>(<i>physical_line, max_line_length, multiline, noqa</i>)
1087 <p>
1088 Limit all lines to a maximum of 79 characters.
1089 </p><p>
1090 There are still many devices around that are limited to 80 character
1091 lines; plus, limiting windows to 80 characters makes it possible to have
1092 several windows side-by-side. The default wrapping on such devices looks
1093 ugly. Therefore, please limit all lines to a maximum of 79 characters.
1094 For flowing long blocks of text (docstrings or comments), limiting the
1095 length to 72 characters is recommended.
1096 </p><p>
1097 Reports error E501.
1098 </p>
1099 <div align="right"><a href="#top">Up</a></div>
1100 <hr /><hr />
1101 <a NAME="missing_whitespace" ID="missing_whitespace"></a>
1102 <h2>missing_whitespace</h2>
1103 <b>missing_whitespace</b>(<i>logical_line</i>)
1104 <p>
1105 Each comma, semicolon or colon should be followed by whitespace.
1106 </p><p>
1107 Okay: [a, b]
1108 Okay: (3,)
1109 Okay: a[1:4]
1110 Okay: a[:4]
1111 Okay: a[1:]
1112 Okay: a[1:4:2]
1113 E231: ['a','b']
1114 E231: foo(bar,baz)
1115 E231: [{'a':'b'}]
1116 </p>
1117 <div align="right"><a href="#top">Up</a></div>
1118 <hr /><hr />
1119 <a NAME="missing_whitespace_after_import_keyword" ID="missing_whitespace_after_import_keyword"></a>
1120 <h2>missing_whitespace_after_import_keyword</h2>
1121 <b>missing_whitespace_after_import_keyword</b>(<i>logical_line</i>)
1122 <p>
1123 Multiple imports in form from x import (a, b, c) should have space
1124 between import statement and parenthesised name list.
1125 </p><p>
1126 Okay: from foo import (bar, baz)
1127 E275: from foo import(bar, baz)
1128 E275: from importable.module import(bar, baz)
1129 </p>
1130 <div align="right"><a href="#top">Up</a></div>
1131 <hr /><hr />
1132 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a>
1133 <h2>missing_whitespace_around_operator</h2>
1134 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>)
1135 <p>
1136 Surround operators with a single space on either side.
1137 </p><p>
1138 - Always surround these binary operators with a single space on
1139 either side: assignment (=), augmented assignment (+=, -= etc.),
1140 comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
1141 Booleans (and, or, not).
1142 </p><p>
1143 - If operators with different priorities are used, consider adding
1144 whitespace around the operators with the lowest priorities.
1145 </p><p>
1146 Okay: i = i + 1
1147 Okay: submitted += 1
1148 Okay: x = x * 2 - 1
1149 Okay: hypot2 = x * x + y * y
1150 Okay: c = (a + b) * (a - b)
1151 Okay: foo(bar, key='word', *args, **kwargs)
1152 Okay: alpha[:-i]
1153 </p><p>
1154 E225: i=i+1
1155 E225: submitted +=1
1156 E225: x = x /2 - 1
1157 E225: z = x **y
1158 E226: c = (a+b) * (a-b)
1159 E226: hypot2 = x*x + y*y
1160 E227: c = a|b
1161 E228: msg = fmt%(errno, errmsg)
1162 </p>
1163 <div align="right"><a href="#top">Up</a></div>
1164 <hr /><hr />
1165 <a NAME="module_imports_on_top_of_file" ID="module_imports_on_top_of_file"></a>
1166 <h2>module_imports_on_top_of_file</h2>
1167 <b>module_imports_on_top_of_file</b>(<i>logical_line, indent_level, checker_state, noqa</i>)
1168 <p>
1169 Place imports at the top of the file.
1170 </p><p>
1171 Always put imports at the top of the file, just after any module comments
1172 and docstrings, and before module globals and constants.
1173 </p><p>
1174 Okay: import os
1175 Okay: # this is a comment\nimport os
1176 Okay: '''this is a module docstring'''\nimport os
1177 Okay: r'''this is a module docstring'''\nimport os
1178 Okay: try:\n import x\nexcept:\n pass\nelse:\n pass\nimport y
1179 Okay: try:\n import x\nexcept:\n pass\nfinally:\n pass\nimport y
1180 E402: a=1\nimport os
1181 E402: 'One string'\n"Two string"\nimport os
1182 E402: a=1\nfrom sys import x
1183 </p><p>
1184 Okay: if x:\n import os
1185 </p>
1186 <div align="right"><a href="#top">Up</a></div>
1187 <hr /><hr />
1188 <a NAME="mute_string" ID="mute_string"></a>
1189 <h2>mute_string</h2>
1190 <b>mute_string</b>(<i>text</i>)
1191 <p>
1192 Replace contents with 'xxx' to prevent syntax matching.
1193 </p><p>
1194 >>> mute_string('"abc"')
1195 '"xxx"'
1196 >>> mute_string("'''abc'''")
1197 "'''xxx'''"
1198 >>> mute_string("r'abc'")
1199 "r'xxx'"
1200 </p>
1201 <div align="right"><a href="#top">Up</a></div>
1202 <hr /><hr />
1203 <a NAME="normalize_paths" ID="normalize_paths"></a>
1204 <h2>normalize_paths</h2>
1205 <b>normalize_paths</b>(<i>value, parent=os.curdir</i>)
1206 <p>
1207 Parse a comma-separated list of paths.
1208 </p><p>
1209 Return a list of absolute paths.
1210 </p>
1211 <div align="right"><a href="#top">Up</a></div>
1212 <hr /><hr />
1213 <a NAME="parse_udiff" ID="parse_udiff"></a>
1214 <h2>parse_udiff</h2>
1215 <b>parse_udiff</b>(<i>diff, patterns=None, parent='.'</i>)
1216 <p>
1217 Return a dictionary of matching lines.
1218 </p>
1219 <div align="right"><a href="#top">Up</a></div>
1220 <hr /><hr />
1221 <a NAME="process_options" ID="process_options"></a>
1222 <h2>process_options</h2>
1223 <b>process_options</b>(<i>arglist=None, parse_argv=False, config_file=None, parser=None</i>)
1224 <p>
1225 Process options passed either via arglist or via command line args.
1226 </p><p>
1227 Passing in the ``config_file`` parameter allows other tools, such as flake8
1228 to specify their own options to be processed in pycodestyle.
1229 </p>
1230 <div align="right"><a href="#top">Up</a></div>
1231 <hr /><hr />
1232 <a NAME="python_3000_backticks" ID="python_3000_backticks"></a>
1233 <h2>python_3000_backticks</h2>
1234 <b>python_3000_backticks</b>(<i>logical_line</i>)
1235 <p>
1236 Use repr() instead of backticks in Python 3.
1237 </p><p>
1238 Okay: val = repr(1 + 2)
1239 W604: val = `1 + 2`
1240 </p>
1241 <div align="right"><a href="#top">Up</a></div>
1242 <hr /><hr />
1243 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a>
1244 <h2>python_3000_has_key</h2>
1245 <b>python_3000_has_key</b>(<i>logical_line, noqa</i>)
1246 <p>
1247 The {}.has_key() method is removed in Python 3: use the 'in' operator.
1248 </p><p>
1249 Okay: if "alph" in d:\n print d["alph"]
1250 W601: assert d.has_key('alph')
1251 </p>
1252 <div align="right"><a href="#top">Up</a></div>
1253 <hr /><hr />
1254 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a>
1255 <h2>python_3000_not_equal</h2>
1256 <b>python_3000_not_equal</b>(<i>logical_line</i>)
1257 <p>
1258 New code should always use != instead of <>.
1259 </p><p>
1260 The older syntax is removed in Python 3.
1261 </p><p>
1262 Okay: if a != 'no':
1263 W603: if a <> 'no':
1264 </p>
1265 <div align="right"><a href="#top">Up</a></div>
1266 <hr /><hr />
1267 <a NAME="python_3000_raise_comma" ID="python_3000_raise_comma"></a>
1268 <h2>python_3000_raise_comma</h2>
1269 <b>python_3000_raise_comma</b>(<i>logical_line</i>)
1270 <p>
1271 When raising an exception, use "raise ValueError('message')".
1272 </p><p>
1273 The older form is removed in Python 3.
1274 </p><p>
1275 Okay: raise DummyError("Message")
1276 W602: raise DummyError, "Message"
1277 </p>
1278 <div align="right"><a href="#top">Up</a></div>
1279 <hr /><hr />
1280 <a NAME="read_config" ID="read_config"></a>
1281 <h2>read_config</h2>
1282 <b>read_config</b>(<i>options, args, arglist, parser</i>)
1283 <p>
1284 Read and parse configurations
1285 </p><p>
1286 If a config file is specified on the command line with the "--config"
1287 option, then only it is used for configuration.
1288 </p><p>
1289 Otherwise, the user configuration (~/.config/pycodestyle) and any local
1290 configurations in the current directory or above will be merged together
1291 (in that order) using the read method of ConfigParser.
1292 </p>
1293 <div align="right"><a href="#top">Up</a></div>
1294 <hr /><hr />
1295 <a NAME="readlines" ID="readlines"></a>
1296 <h2>readlines</h2>
1297 <b>readlines</b>(<i>filename</i>)
1298 <p>
1299 Read the source code.
1300 </p>
1301 <div align="right"><a href="#top">Up</a></div>
1302 <hr /><hr />
1303 <a NAME="readlines_1" ID="readlines_1"></a>
1304 <h2>readlines</h2>
1305 <b>readlines</b>(<i>filename</i>)
1306 <p>
1307 Read the source code.
1308 </p>
1309 <div align="right"><a href="#top">Up</a></div>
1310 <hr /><hr />
1311 <a NAME="register_check" ID="register_check"></a>
1312 <h2>register_check</h2>
1313 <b>register_check</b>(<i>check, codes=None</i>)
1314 <p>
1315 Register a new check object.
1316 </p>
1317 <div align="right"><a href="#top">Up</a></div>
1318 <hr /><hr />
1319 <a NAME="stdin_get_value" ID="stdin_get_value"></a>
1320 <h2>stdin_get_value</h2>
1321 <b>stdin_get_value</b>(<i></i>)
1322 <p>
1323 Read the value from stdin.
1324 </p>
1325 <div align="right"><a href="#top">Up</a></div>
1326 <hr /><hr />
1327 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a>
1328 <h2>tabs_obsolete</h2>
1329 <b>tabs_obsolete</b>(<i>physical_line</i>)
1330 <p>
1331 For new projects, spaces-only are strongly recommended over tabs.
1332 </p><p>
1333 Okay: if True:\n return
1334 W191: if True:\n\treturn
1335 </p>
1336 <div align="right"><a href="#top">Up</a></div>
1337 <hr /><hr />
1338 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a>
1339 <h2>tabs_or_spaces</h2>
1340 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>)
1341 <p>
1342 Never mix tabs and spaces.
1343 </p><p>
1344 The most popular way of indenting Python is with spaces only. The
1345 second-most popular way is with tabs only. Code indented with a mixture
1346 of tabs and spaces should be converted to using spaces exclusively. When
1347 invoking the Python command line interpreter with the -t option, it issues
1348 warnings about code that illegally mixes tabs and spaces. When using -tt
1349 these warnings become errors. These options are highly recommended!
1350 </p><p>
1351 Okay: if a == 0:\n a = 1\n b = 1
1352 E101: if a == 0:\n a = 1\n\tb = 1
1353 </p>
1354 <div align="right"><a href="#top">Up</a></div>
1355 <hr /><hr />
1356 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a>
1357 <h2>trailing_blank_lines</h2>
1358 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number, total_lines</i>)
1359 <p>
1360 Trailing blank lines are superfluous.
1361 </p><p>
1362 Okay: spam(1)
1363 W391: spam(1)\n
1364 </p><p>
1365 However the last line should end with a new line (warning W292).
1366 </p>
1367 <div align="right"><a href="#top">Up</a></div>
1368 <hr /><hr />
1369 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a>
1370 <h2>trailing_whitespace</h2>
1371 <b>trailing_whitespace</b>(<i>physical_line</i>)
1372 <p>
1373 Trailing whitespace is superfluous.
1374 </p><p>
1375 The warning returned varies on whether the line itself is blank, for easier
1376 filtering for those who want to indent their blank lines.
1377 </p><p>
1378 Okay: spam(1)\n#
1379 W291: spam(1) \n#
1380 W293: class Foo(object):\n \n bang = 12
1381 </p>
1382 <div align="right"><a href="#top">Up</a></div>
1383 <hr /><hr />
1384 <a NAME="update_counts" ID="update_counts"></a>
1385 <h2>update_counts</h2>
1386 <b>update_counts</b>(<i>s, counts</i>)
1387 <p>
1388 Adds one to the counts of each appearance of characters in s,
1389 for characters in counts
1390 </p>
1391 <div align="right"><a href="#top">Up</a></div>
1392 <hr /><hr />
1393 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a>
1394 <h2>whitespace_around_comma</h2>
1395 <b>whitespace_around_comma</b>(<i>logical_line</i>)
1396 <p>
1397 Avoid extraneous whitespace after a comma or a colon.
1398 </p><p>
1399 Note: these checks are disabled by default
1400 </p><p>
1401 Okay: a = (1, 2)
1402 E241: a = (1, 2)
1403 E242: a = (1,\t2)
1404 </p>
1405 <div align="right"><a href="#top">Up</a></div>
1406 <hr /><hr />
1407 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a>
1408 <h2>whitespace_around_keywords</h2>
1409 <b>whitespace_around_keywords</b>(<i>logical_line</i>)
1410 <p>
1411 Avoid extraneous whitespace around keywords.
1412 </p><p>
1413 Okay: True and False
1414 E271: True and False
1415 E272: True and False
1416 E273: True and\tFalse
1417 E274: True\tand False
1418 </p>
1419 <div align="right"><a href="#top">Up</a></div>
1420 <hr /><hr />
1421 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a>
1422 <h2>whitespace_around_named_parameter_equals</h2>
1423 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>)
1424 <p>
1425 Don't use spaces around the '=' sign in function arguments.
1426 </p><p>
1427 Don't use spaces around the '=' sign when used to indicate a
1428 keyword argument or a default parameter value.
1429 </p><p>
1430 Okay: def complex(real, imag=0.0):
1431 Okay: return magic(r=real, i=imag)
1432 Okay: boolean(a == b)
1433 Okay: boolean(a != b)
1434 Okay: boolean(a <= b)
1435 Okay: boolean(a >= b)
1436 Okay: def foo(arg: int = 42):
1437 Okay: async def foo(arg: int = 42):
1438 </p><p>
1439 E251: def complex(real, imag = 0.0):
1440 E251: return magic(r = real, i = imag)
1441 </p>
1442 <div align="right"><a href="#top">Up</a></div>
1443 <hr /><hr />
1444 <a NAME="whitespace_around_operator" ID="whitespace_around_operator"></a>
1445 <h2>whitespace_around_operator</h2>
1446 <b>whitespace_around_operator</b>(<i>logical_line</i>)
1447 <p>
1448 Avoid extraneous whitespace around an operator.
1449 </p><p>
1450 Okay: a = 12 + 3
1451 E221: a = 4 + 5
1452 E222: a = 4 + 5
1453 E223: a = 4\t+ 5
1454 E224: a = 4 +\t5
1455 </p>
1456 <div align="right"><a href="#top">Up</a></div>
1457 <hr /><hr />
1458 <a NAME="whitespace_before_comment" ID="whitespace_before_comment"></a>
1459 <h2>whitespace_before_comment</h2>
1460 <b>whitespace_before_comment</b>(<i>logical_line, tokens</i>)
1461 <p>
1462 Separate inline comments by at least two spaces.
1463 </p><p>
1464 An inline comment is a comment on the same line as a statement. Inline
1465 comments should be separated by at least two spaces from the statement.
1466 They should start with a # and a single space.
1467 </p><p>
1468 Each line of a block comment starts with a # and a single space
1469 (unless it is indented text inside the comment).
1470 </p><p>
1471 Okay: x = x + 1 # Increment x
1472 Okay: x = x + 1 # Increment x
1473 Okay: # Block comment
1474 E261: x = x + 1 # Increment x
1475 E262: x = x + 1 #Increment x
1476 E262: x = x + 1 # Increment x
1477 E265: #Block comment
1478 E266: ### Block comment
1479 </p>
1480 <div align="right"><a href="#top">Up</a></div>
1481 <hr /><hr />
1482 <a NAME="whitespace_before_parameters" ID="whitespace_before_parameters"></a>
1483 <h2>whitespace_before_parameters</h2>
1484 <b>whitespace_before_parameters</b>(<i>logical_line, tokens</i>)
1485 <p>
1486 Avoid extraneous whitespace.
1487 </p><p>
1488 Avoid extraneous whitespace in the following situations:
1489 - before the open parenthesis that starts the argument list of a
1490 function call.
1491 - before the open parenthesis that starts an indexing or slicing.
1492 </p><p>
1493 Okay: spam(1)
1494 E211: spam (1)
1495 </p><p>
1496 Okay: dict['key'] = list[index]
1497 E211: dict ['key'] = list[index]
1498 E211: dict['key'] = list [index]
1499 </p>
1500 <div align="right"><a href="#top">Up</a></div>
1501 <hr />
1502 </body></html>

eric ide

mercurial