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

changeset 3621
15f23ed3f216
parent 3484
645c12de6b0c
equal deleted inserted replaced
3620:2c8d96d47cda 3621:15f23ed3f216
21 <body><a NAME="top" ID="top"></a> 21 <body><a NAME="top" ID="top"></a>
22 <h1>eric5.Plugins.CheckerPlugins.CodeStyleChecker.pep8</h1> 22 <h1>eric5.Plugins.CheckerPlugins.CodeStyleChecker.pep8</h1>
23 23
24 <h3>Global Attributes</h3> 24 <h3>Global Attributes</h3>
25 <table> 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>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> 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>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> 27 </table>
28 <h3>Classes</h3> 28 <h3>Classes</h3>
29 <table> 29 <table>
30 <tr> 30 <tr>
31 <td><a href="#BaseReport">BaseReport</a></td> 31 <td><a href="#BaseReport">BaseReport</a></td>
51 <table> 51 <table>
52 <tr> 52 <tr>
53 <td><a href="#_add_check">_add_check</a></td> 53 <td><a href="#_add_check">_add_check</a></td>
54 <td></td> 54 <td></td>
55 </tr><tr> 55 </tr><tr>
56 <td><a href="#_is_eol_token">_is_eol_token</a></td>
57 <td></td>
58 </tr><tr>
59 <td><a href="#_is_eol_token_1">_is_eol_token</a></td>
60 <td></td>
61 </tr><tr>
56 <td><a href="#_main">_main</a></td> 62 <td><a href="#_main">_main</a></td>
57 <td>Parse options and run checks on Python source.</td> 63 <td>Parse options and run checks on Python source.</td>
58 </tr><tr> 64 </tr><tr>
59 <td><a href="#blank_lines">blank_lines</a></td> 65 <td><a href="#blank_lines">blank_lines</a></td>
60 <td>Separate top-level function and class definitions with two blank lines.</td> 66 <td>Separate top-level function and class definitions with two blank lines.</td>
61 </tr><tr> 67 </tr><tr>
68 <td><a href="#comparison_negative">comparison_negative</a></td>
69 <td>Negative comparison should be done using "not in" and "is not".</td>
70 </tr><tr>
62 <td><a href="#comparison_to_singleton">comparison_to_singleton</a></td> 71 <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> 72 <td>Comparison to singletons should use "is" or "is not".</td>
64 </tr><tr> 73 </tr><tr>
65 <td><a href="#comparison_type">comparison_type</a></td> 74 <td><a href="#comparison_type">comparison_type</a></td>
66 <td>Object type comparisons should always use isinstance() instead of comparing types directly.</td> 75 <td>Object type comparisons should always use isinstance().</td>
67 </tr><tr> 76 </tr><tr>
68 <td><a href="#compound_statements">compound_statements</a></td> 77 <td><a href="#compound_statements">compound_statements</a></td>
69 <td>Compound statements (multiple statements on the same line) are generally discouraged.</td> 78 <td>Compound statements (on the same line) are generally discouraged.</td>
70 </tr><tr> 79 </tr><tr>
71 <td><a href="#continued_indentation">continued_indentation</a></td> 80 <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> 81 <td>Continuation lines indentation.</td>
73 </tr><tr> 82 </tr><tr>
74 <td><a href="#expand_indent">expand_indent</a></td> 83 <td><a href="#expand_indent">expand_indent</a></td>
75 <td>Return the amount of indentation.</td> 84 <td>Return the amount of indentation.</td>
76 </tr><tr> 85 </tr><tr>
77 <td><a href="#explicit_line_join">explicit_line_join</a></td> 86 <td><a href="#explicit_line_join">explicit_line_join</a></td>
78 <td>Avoid explicit line join between brackets.</td> 87 <td>Avoid explicit line join between brackets.</td>
79 </tr><tr> 88 </tr><tr>
80 <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td> 89 <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td>
81 <td>Avoid extraneous whitespace in the following situations:</td> 90 <td>Avoid extraneous whitespace.</td>
82 </tr><tr> 91 </tr><tr>
83 <td><a href="#filename_match">filename_match</a></td> 92 <td><a href="#filename_match">filename_match</a></td>
84 <td>Check if patterns contains a pattern that matches filename.</td> 93 <td>Check if patterns contains a pattern that matches filename.</td>
85 </tr><tr> 94 </tr><tr>
86 <td><a href="#get_parser">get_parser</a></td> 95 <td><a href="#get_parser">get_parser</a></td>
91 </tr><tr> 100 </tr><tr>
92 <td><a href="#indentation">indentation</a></td> 101 <td><a href="#indentation">indentation</a></td>
93 <td>Use 4 spaces per indentation level.</td> 102 <td>Use 4 spaces per indentation level.</td>
94 </tr><tr> 103 </tr><tr>
95 <td><a href="#init_checks_registry">init_checks_registry</a></td> 104 <td><a href="#init_checks_registry">init_checks_registry</a></td>
96 <td>Register all globally visible functions where the first argument name is 'physical_line' or 'logical_line'.</td> 105 <td>Register all globally visible functions.</td>
97 </tr><tr> 106 </tr><tr>
98 <td><a href="#maximum_line_length">maximum_line_length</a></td> 107 <td><a href="#maximum_line_length">maximum_line_length</a></td>
99 <td>Limit all lines to a maximum of 79 characters.</td> 108 <td>Limit all lines to a maximum of 79 characters.</td>
100 </tr><tr> 109 </tr><tr>
101 <td><a href="#missing_newline">missing_newline</a></td>
102 <td>JCR: The last line should have a newline.</td>
103 </tr><tr>
104 <td><a href="#missing_whitespace">missing_whitespace</a></td> 110 <td><a href="#missing_whitespace">missing_whitespace</a></td>
105 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td> 111 <td>Each comma, semicolon or colon should be followed by whitespace.</td>
106 </tr><tr> 112 </tr><tr>
107 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td> 113 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td>
108 <td>- Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).</td> 114 <td>Surround operators with a single space on either side.</td>
109 </tr><tr> 115 </tr><tr>
110 <td><a href="#mute_string">mute_string</a></td> 116 <td><a href="#mute_string">mute_string</a></td>
111 <td>Replace contents with 'xxx' to prevent syntax matching.</td> 117 <td>Replace contents with 'xxx' to prevent syntax matching.</td>
112 </tr><tr> 118 </tr><tr>
119 <td><a href="#normalize_paths">normalize_paths</a></td>
120 <td>Parse a comma-separated list of paths.</td>
121 </tr><tr>
113 <td><a href="#parse_udiff">parse_udiff</a></td> 122 <td><a href="#parse_udiff">parse_udiff</a></td>
114 <td>Return a dictionary of matching lines.</td> 123 <td>Return a dictionary of matching lines.</td>
115 </tr><tr> 124 </tr><tr>
116 <td><a href="#process_options">process_options</a></td> 125 <td><a href="#process_options">process_options</a></td>
117 <td>Process options passed either via arglist or via command line args.</td> 126 <td>Process options passed either via arglist or via command line args.</td>
118 </tr><tr> 127 </tr><tr>
119 <td><a href="#python_3000_backticks">python_3000_backticks</a></td> 128 <td><a href="#python_3000_backticks">python_3000_backticks</a></td>
120 <td>Backticks are removed in Python 3.</td> 129 <td>Backticks are removed in Python 3: use repr() instead.</td>
121 </tr><tr> 130 </tr><tr>
122 <td><a href="#python_3000_has_key">python_3000_has_key</a></td> 131 <td><a href="#python_3000_has_key">python_3000_has_key</a></td>
123 <td>The {}.has_key() method is removed in the Python 3.</td> 132 <td>The {}.has_key() method is removed in Python 3: use the 'in' operator.</td>
124 </tr><tr> 133 </tr><tr>
125 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td> 134 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td>
126 <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td> 135 <td>New code should always use != instead of <>.</td>
127 </tr><tr> 136 </tr><tr>
128 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td> 137 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td>
129 <td>When raising an exception, use "raise ValueError('message')" instead of the older form "raise ValueError, 'message'".</td> 138 <td>When raising an exception, use "raise ValueError('message')".</td>
130 </tr><tr> 139 </tr><tr>
131 <td><a href="#read_config">read_config</a></td> 140 <td><a href="#read_config">read_config</a></td>
132 <td>Read both user configuration and local configuration.</td> 141 <td>Read both user configuration and local configuration.</td>
133 </tr><tr> 142 </tr><tr>
134 <td><a href="#readlines">readlines</a></td> 143 <td><a href="#readlines">readlines</a></td>
135 <td></td> 144 <td>Read the source code.</td>
136 </tr><tr> 145 </tr><tr>
137 <td><a href="#readlines_1">readlines</a></td> 146 <td><a href="#readlines_1">readlines</a></td>
138 <td></td> 147 <td>Read the source code.</td>
139 </tr><tr> 148 </tr><tr>
140 <td><a href="#register_check">register_check</a></td> 149 <td><a href="#register_check">register_check</a></td>
141 <td>Register a new check object.</td> 150 <td>Register a new check object.</td>
142 </tr><tr> 151 </tr><tr>
143 <td><a href="#stdin_get_value">stdin_get_value</a></td> 152 <td><a href="#stdin_get_value">stdin_get_value</a></td>
148 </tr><tr> 157 </tr><tr>
149 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td> 158 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td>
150 <td>Never mix tabs and spaces.</td> 159 <td>Never mix tabs and spaces.</td>
151 </tr><tr> 160 </tr><tr>
152 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td> 161 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td>
153 <td>JCR: Trailing blank lines are superfluous.</td> 162 <td>Trailing blank lines are superfluous.</td>
154 </tr><tr> 163 </tr><tr>
155 <td><a href="#trailing_whitespace">trailing_whitespace</a></td> 164 <td><a href="#trailing_whitespace">trailing_whitespace</a></td>
156 <td>JCR: Trailing whitespace is superfluous.</td> 165 <td>Trailing whitespace is superfluous.</td>
157 </tr><tr> 166 </tr><tr>
158 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td> 167 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td>
159 <td>Avoid extraneous whitespace in the following situations:</td> 168 <td>Avoid extraneous whitespace after a comma or a colon.</td>
160 </tr><tr> 169 </tr><tr>
161 <td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td> 170 <td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td>
162 <td>Avoid extraneous whitespace around keywords.</td> 171 <td>Avoid extraneous whitespace around keywords.</td>
163 </tr><tr> 172 </tr><tr>
164 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td> 173 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td>
165 <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td> 174 <td>Don't use spaces around the '=' sign in function arguments.</td>
166 </tr><tr> 175 </tr><tr>
167 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td> 176 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td>
168 <td>Avoid extraneous whitespace in the following situations:</td> 177 <td>Avoid extraneous whitespace around an operator.</td>
169 </tr><tr> 178 </tr><tr>
170 <td><a href="#whitespace_before_inline_comment">whitespace_before_inline_comment</a></td> 179 <td><a href="#whitespace_before_comment">whitespace_before_comment</a></td>
171 <td>Separate inline comments by at least two spaces.</td> 180 <td>Separate inline comments by at least two spaces.</td>
172 </tr><tr> 181 </tr><tr>
173 <td><a href="#whitespace_before_parameters">whitespace_before_parameters</a></td> 182 <td><a href="#whitespace_before_parameters">whitespace_before_parameters</a></td>
174 <td>Avoid extraneous whitespace in the following situations:</td> 183 <td>Avoid extraneous whitespace.</td>
175 </tr> 184 </tr>
176 </table> 185 </table>
177 <hr /><hr /> 186 <hr /><hr />
178 <a NAME="BaseReport" ID="BaseReport"></a> 187 <a NAME="BaseReport" ID="BaseReport"></a>
179 <h2>BaseReport</h2> 188 <h2>BaseReport</h2>
242 <b>error</b>(<i>line_number, offset, text, check</i>) 251 <b>error</b>(<i>line_number, offset, text, check</i>)
243 <p> 252 <p>
244 Report an error, according to options. 253 Report an error, according to options.
245 </p><a NAME="BaseReport.error_args" ID="BaseReport.error_args"></a> 254 </p><a NAME="BaseReport.error_args" ID="BaseReport.error_args"></a>
246 <h4>BaseReport.error_args</h4> 255 <h4>BaseReport.error_args</h4>
247 <b>error_args</b>(<i>line_number, offset, code, check, *args</i>) 256 <b>error_args</b>(<i>line_number, offset, text, check, *args</i>)
248 <p> 257 <p>
249 Report an error, according to options. 258 Report an error, according to options.
250 </p><a NAME="BaseReport.get_count" ID="BaseReport.get_count"></a> 259 </p><a NAME="BaseReport.get_count" ID="BaseReport.get_count"></a>
251 <h4>BaseReport.get_count</h4> 260 <h4>BaseReport.get_count</h4>
252 <b>get_count</b>(<i>prefix=''</i>) 261 <b>get_count</b>(<i>prefix=''</i>)
259 Return the count of errors and warnings for this file. 268 Return the count of errors and warnings for this file.
260 </p><a NAME="BaseReport.get_statistics" ID="BaseReport.get_statistics"></a> 269 </p><a NAME="BaseReport.get_statistics" ID="BaseReport.get_statistics"></a>
261 <h4>BaseReport.get_statistics</h4> 270 <h4>BaseReport.get_statistics</h4>
262 <b>get_statistics</b>(<i>prefix=''</i>) 271 <b>get_statistics</b>(<i>prefix=''</i>)
263 <p> 272 <p>
264 Get statistics for message codes that start with the prefix. 273 Get statistics for message codes that start with the prefix.
265 </p><p> 274 </p><p>
266 prefix='' matches all errors and warnings 275 prefix='' matches all errors and warnings
267 prefix='E' matches all errors 276 prefix='E' matches all errors
268 prefix='W' matches all warnings 277 prefix='W' matches all warnings
269 prefix='E4' matches all errors that have to do with imports 278 prefix='E4' matches all errors that have to do with imports
301 <div align="right"><a href="#top">Up</a></div> 310 <div align="right"><a href="#top">Up</a></div>
302 <hr /><hr /> 311 <hr /><hr />
303 <a NAME="Checker" ID="Checker"></a> 312 <a NAME="Checker" ID="Checker"></a>
304 <h2>Checker</h2> 313 <h2>Checker</h2>
305 <p> 314 <p>
306 Load a Python source file, tokenize it, check coding style. 315 Load a Python source file, tokenize it, check coding style.
307 </p> 316 </p>
308 <h3>Derived from</h3> 317 <h3>Derived from</h3>
309 object 318 object
310 <h3>Class Attributes</h3> 319 <h3>Class Attributes</h3>
311 <table> 320 <table>
326 </tr><tr> 335 </tr><tr>
327 <td><a href="#Checker.check_all">check_all</a></td> 336 <td><a href="#Checker.check_all">check_all</a></td>
328 <td>Run all checks on the input file.</td> 337 <td>Run all checks on the input file.</td>
329 </tr><tr> 338 </tr><tr>
330 <td><a href="#Checker.check_ast">check_ast</a></td> 339 <td><a href="#Checker.check_ast">check_ast</a></td>
331 <td></td> 340 <td>Build the file's AST and run all AST checks.</td>
332 </tr><tr> 341 </tr><tr>
333 <td><a href="#Checker.check_logical">check_logical</a></td> 342 <td><a href="#Checker.check_logical">check_logical</a></td>
334 <td>Build a line from tokens and run all logical checks on it.</td> 343 <td>Build a line from tokens and run all logical checks on it.</td>
335 </tr><tr> 344 </tr><tr>
336 <td><a href="#Checker.check_physical">check_physical</a></td> 345 <td><a href="#Checker.check_physical">check_physical</a></td>
337 <td>Run all physical checks on a raw input line.</td> 346 <td>Run all physical checks on a raw input line.</td>
338 </tr><tr> 347 </tr><tr>
339 <td><a href="#Checker.generate_tokens">generate_tokens</a></td> 348 <td><a href="#Checker.generate_tokens">generate_tokens</a></td>
340 <td></td> 349 <td>Tokenize the file, run physical line checks and yield tokens.</td>
350 </tr><tr>
351 <td><a href="#Checker.maybe_check_physical">maybe_check_physical</a></td>
352 <td>If appropriate (based on token), check current physical line(s).</td>
341 </tr><tr> 353 </tr><tr>
342 <td><a href="#Checker.readline">readline</a></td> 354 <td><a href="#Checker.readline">readline</a></td>
343 <td>Get the next line from the input buffer.</td> 355 <td>Get the next line from the input buffer.</td>
344 </tr><tr> 356 </tr><tr>
345 <td><a href="#Checker.readline_check_physical">readline_check_physical</a></td>
346 <td>Check and return the next physical line.</td>
347 </tr><tr>
348 <td><a href="#Checker.report_invalid_syntax">report_invalid_syntax</a></td> 357 <td><a href="#Checker.report_invalid_syntax">report_invalid_syntax</a></td>
349 <td></td> 358 <td>Check if the syntax is valid.</td>
350 </tr><tr> 359 </tr><tr>
351 <td><a href="#Checker.run_check">run_check</a></td> 360 <td><a href="#Checker.run_check">run_check</a></td>
352 <td>Run a check plugin.</td> 361 <td>Run a check plugin.</td>
353 </tr> 362 </tr>
354 </table> 363 </table>
361 <b>Checker</b>(<i>filename=None, lines=None, options=None, report=None, **kwargs</i>) 370 <b>Checker</b>(<i>filename=None, lines=None, options=None, report=None, **kwargs</i>)
362 <a NAME="Checker.build_tokens_line" ID="Checker.build_tokens_line"></a> 371 <a NAME="Checker.build_tokens_line" ID="Checker.build_tokens_line"></a>
363 <h4>Checker.build_tokens_line</h4> 372 <h4>Checker.build_tokens_line</h4>
364 <b>build_tokens_line</b>(<i></i>) 373 <b>build_tokens_line</b>(<i></i>)
365 <p> 374 <p>
366 Build a logical line from tokens. 375 Build a logical line from tokens.
367 </p><a NAME="Checker.check_all" ID="Checker.check_all"></a> 376 </p><a NAME="Checker.check_all" ID="Checker.check_all"></a>
368 <h4>Checker.check_all</h4> 377 <h4>Checker.check_all</h4>
369 <b>check_all</b>(<i>expected=None, line_offset=0</i>) 378 <b>check_all</b>(<i>expected=None, line_offset=0</i>)
370 <p> 379 <p>
371 Run all checks on the input file. 380 Run all checks on the input file.
372 </p><a NAME="Checker.check_ast" ID="Checker.check_ast"></a> 381 </p><a NAME="Checker.check_ast" ID="Checker.check_ast"></a>
373 <h4>Checker.check_ast</h4> 382 <h4>Checker.check_ast</h4>
374 <b>check_ast</b>(<i></i>) 383 <b>check_ast</b>(<i></i>)
375 <a NAME="Checker.check_logical" ID="Checker.check_logical"></a> 384 <p>
385 Build the file's AST and run all AST checks.
386 </p><a NAME="Checker.check_logical" ID="Checker.check_logical"></a>
376 <h4>Checker.check_logical</h4> 387 <h4>Checker.check_logical</h4>
377 <b>check_logical</b>(<i></i>) 388 <b>check_logical</b>(<i></i>)
378 <p> 389 <p>
379 Build a line from tokens and run all logical checks on it. 390 Build a line from tokens and run all logical checks on it.
380 </p><a NAME="Checker.check_physical" ID="Checker.check_physical"></a> 391 </p><a NAME="Checker.check_physical" ID="Checker.check_physical"></a>
381 <h4>Checker.check_physical</h4> 392 <h4>Checker.check_physical</h4>
382 <b>check_physical</b>(<i>line</i>) 393 <b>check_physical</b>(<i>line</i>)
383 <p> 394 <p>
384 Run all physical checks on a raw input line. 395 Run all physical checks on a raw input line.
385 </p><a NAME="Checker.generate_tokens" ID="Checker.generate_tokens"></a> 396 </p><a NAME="Checker.generate_tokens" ID="Checker.generate_tokens"></a>
386 <h4>Checker.generate_tokens</h4> 397 <h4>Checker.generate_tokens</h4>
387 <b>generate_tokens</b>(<i></i>) 398 <b>generate_tokens</b>(<i></i>)
388 <a NAME="Checker.readline" ID="Checker.readline"></a> 399 <p>
400 Tokenize the file, run physical line checks and yield tokens.
401 </p><a NAME="Checker.maybe_check_physical" ID="Checker.maybe_check_physical"></a>
402 <h4>Checker.maybe_check_physical</h4>
403 <b>maybe_check_physical</b>(<i>token</i>)
404 <p>
405 If appropriate (based on token), check current physical line(s).
406 </p><a NAME="Checker.readline" ID="Checker.readline"></a>
389 <h4>Checker.readline</h4> 407 <h4>Checker.readline</h4>
390 <b>readline</b>(<i></i>) 408 <b>readline</b>(<i></i>)
391 <p> 409 <p>
392 Get the next line from the input buffer. 410 Get the next line from the input buffer.
393 </p><a NAME="Checker.readline_check_physical" ID="Checker.readline_check_physical"></a>
394 <h4>Checker.readline_check_physical</h4>
395 <b>readline_check_physical</b>(<i></i>)
396 <p>
397 Check and return the next physical line. This method can be
398 used to feed tokenize.generate_tokens.
399 </p><a NAME="Checker.report_invalid_syntax" ID="Checker.report_invalid_syntax"></a> 411 </p><a NAME="Checker.report_invalid_syntax" ID="Checker.report_invalid_syntax"></a>
400 <h4>Checker.report_invalid_syntax</h4> 412 <h4>Checker.report_invalid_syntax</h4>
401 <b>report_invalid_syntax</b>(<i></i>) 413 <b>report_invalid_syntax</b>(<i></i>)
402 <a NAME="Checker.run_check" ID="Checker.run_check"></a> 414 <p>
415 Check if the syntax is valid.
416 </p><a NAME="Checker.run_check" ID="Checker.run_check"></a>
403 <h4>Checker.run_check</h4> 417 <h4>Checker.run_check</h4>
404 <b>run_check</b>(<i>check, argument_names</i>) 418 <b>run_check</b>(<i>check, argument_names</i>)
405 <p> 419 <p>
406 Run a check plugin. 420 Run a check plugin.
407 </p> 421 </p>
408 <div align="right"><a href="#top">Up</a></div> 422 <div align="right"><a href="#top">Up</a></div>
409 <hr /><hr /> 423 <hr /><hr />
410 <a NAME="DiffReport" ID="DiffReport"></a> 424 <a NAME="DiffReport" ID="DiffReport"></a>
411 <h2>DiffReport</h2> 425 <h2>DiffReport</h2>
558 </tr><tr> 572 </tr><tr>
559 <td><a href="#StyleGuide.check_files">check_files</a></td> 573 <td><a href="#StyleGuide.check_files">check_files</a></td>
560 <td>Run all checks on the paths.</td> 574 <td>Run all checks on the paths.</td>
561 </tr><tr> 575 </tr><tr>
562 <td><a href="#StyleGuide.excluded">excluded</a></td> 576 <td><a href="#StyleGuide.excluded">excluded</a></td>
563 <td>Check if options.exclude contains a pattern that matches filename.</td> 577 <td>Check if the file should be excluded.</td>
564 </tr><tr> 578 </tr><tr>
565 <td><a href="#StyleGuide.get_checks">get_checks</a></td> 579 <td><a href="#StyleGuide.get_checks">get_checks</a></td>
566 <td>Find all globally visible functions where the first argument name starts with argument_name and which contain selected tests.</td> 580 <td>Get all the checks for this category.</td>
567 </tr><tr> 581 </tr><tr>
568 <td><a href="#StyleGuide.ignore_code">ignore_code</a></td> 582 <td><a href="#StyleGuide.ignore_code">ignore_code</a></td>
569 <td>Check if the error code should be ignored.</td> 583 <td>Check if the error code should be ignored.</td>
570 </tr><tr> 584 </tr><tr>
571 <td><a href="#StyleGuide.init_report">init_report</a></td> 585 <td><a href="#StyleGuide.init_report">init_report</a></td>
592 Run all checks on the paths. 606 Run all checks on the paths.
593 </p><a NAME="StyleGuide.excluded" ID="StyleGuide.excluded"></a> 607 </p><a NAME="StyleGuide.excluded" ID="StyleGuide.excluded"></a>
594 <h4>StyleGuide.excluded</h4> 608 <h4>StyleGuide.excluded</h4>
595 <b>excluded</b>(<i>filename, parent=None</i>) 609 <b>excluded</b>(<i>filename, parent=None</i>)
596 <p> 610 <p>
597 Check if options.exclude contains a pattern that matches filename. 611 Check if the file should be excluded.
612 </p><p>
613 Check if 'options.exclude' contains a pattern that matches filename.
598 </p><a NAME="StyleGuide.get_checks" ID="StyleGuide.get_checks"></a> 614 </p><a NAME="StyleGuide.get_checks" ID="StyleGuide.get_checks"></a>
599 <h4>StyleGuide.get_checks</h4> 615 <h4>StyleGuide.get_checks</h4>
600 <b>get_checks</b>(<i>argument_name</i>) 616 <b>get_checks</b>(<i>argument_name</i>)
601 <p> 617 <p>
618 Get all the checks for this category.
619 </p><p>
602 Find all globally visible functions where the first argument name 620 Find all globally visible functions where the first argument name
603 starts with argument_name and which contain selected tests. 621 starts with argument_name and which contain selected tests.
604 </p><a NAME="StyleGuide.ignore_code" ID="StyleGuide.ignore_code"></a> 622 </p><a NAME="StyleGuide.ignore_code" ID="StyleGuide.ignore_code"></a>
605 <h4>StyleGuide.ignore_code</h4> 623 <h4>StyleGuide.ignore_code</h4>
606 <b>ignore_code</b>(<i>code</i>) 624 <b>ignore_code</b>(<i>code</i>)
607 <p> 625 <p>
608 Check if the error code should be ignored. 626 Check if the error code should be ignored.
609 </p><p> 627 </p><p>
610 If 'options.select' contains a prefix of the error code, 628 If 'options.select' contains a prefix of the error code,
611 return False. Else, if 'options.ignore' contains a prefix of 629 return False. Else, if 'options.ignore' contains a prefix of
612 the error code, return True. 630 the error code, return True.
613 </p><a NAME="StyleGuide.init_report" ID="StyleGuide.init_report"></a> 631 </p><a NAME="StyleGuide.init_report" ID="StyleGuide.init_report"></a>
632 <h2>_add_check</h2> 650 <h2>_add_check</h2>
633 <b>_add_check</b>(<i>check, kind, codes, args</i>) 651 <b>_add_check</b>(<i>check, kind, codes, args</i>)
634 652
635 <div align="right"><a href="#top">Up</a></div> 653 <div align="right"><a href="#top">Up</a></div>
636 <hr /><hr /> 654 <hr /><hr />
655 <a NAME="_is_eol_token" ID="_is_eol_token"></a>
656 <h2>_is_eol_token</h2>
657 <b>_is_eol_token</b>(<i>token</i>)
658
659 <div align="right"><a href="#top">Up</a></div>
660 <hr /><hr />
661 <a NAME="_is_eol_token_1" ID="_is_eol_token_1"></a>
662 <h2>_is_eol_token</h2>
663 <b>_is_eol_token</b>(<i>token</i>)
664
665 <div align="right"><a href="#top">Up</a></div>
666 <hr /><hr />
637 <a NAME="_main" ID="_main"></a> 667 <a NAME="_main" ID="_main"></a>
638 <h2>_main</h2> 668 <h2>_main</h2>
639 <b>_main</b>(<i></i>) 669 <b>_main</b>(<i></i>)
640 <p> 670 <p>
641 Parse options and run checks on Python source. 671 Parse options and run checks on Python source.
642 </p> 672 </p>
643 <div align="right"><a href="#top">Up</a></div> 673 <div align="right"><a href="#top">Up</a></div>
644 <hr /><hr /> 674 <hr /><hr />
645 <a NAME="blank_lines" ID="blank_lines"></a> 675 <a NAME="blank_lines" ID="blank_lines"></a>
646 <h2>blank_lines</h2> 676 <h2>blank_lines</h2>
647 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level</i>) 677 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, blank_before, previous_logical, previous_indent_level</i>)
648 <p> 678 <p>
649 Separate top-level function and class definitions with two blank lines. 679 Separate top-level function and class definitions with two blank lines.
650 </p><p> 680 </p><p>
651 Method definitions inside a class are separated by a single blank line. 681 Method definitions inside a class are separated by a single blank line.
652 </p><p> 682 </p><p>
653 Extra blank lines may be used (sparingly) to separate groups of related 683 Extra blank lines may be used (sparingly) to separate groups of related
654 functions. Blank lines may be omitted between a bunch of related 684 functions. Blank lines may be omitted between a bunch of related
665 E303: def a():\n\n\n\n pass 695 E303: def a():\n\n\n\n pass
666 E304: @decorator\n\ndef a():\n pass 696 E304: @decorator\n\ndef a():\n pass
667 </p> 697 </p>
668 <div align="right"><a href="#top">Up</a></div> 698 <div align="right"><a href="#top">Up</a></div>
669 <hr /><hr /> 699 <hr /><hr />
700 <a NAME="comparison_negative" ID="comparison_negative"></a>
701 <h2>comparison_negative</h2>
702 <b>comparison_negative</b>(<i>logical_line</i>)
703 <p>
704 Negative comparison should be done using "not in" and "is not".
705 </p><p>
706 Okay: if x not in y:\n pass
707 Okay: assert (X in Y or X is Z)
708 Okay: if not (X in Y):\n pass
709 Okay: zz = x is not y
710 E713: Z = not X in Y
711 E713: if not X.B in Y:\n pass
712 E714: if not X is Y:\n pass
713 E714: Z = not X.B is Y
714 </p>
715 <div align="right"><a href="#top">Up</a></div>
716 <hr /><hr />
670 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a> 717 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a>
671 <h2>comparison_to_singleton</h2> 718 <h2>comparison_to_singleton</h2>
672 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>) 719 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>)
673 <p> 720 <p>
721 Comparison to singletons should use "is" or "is not".
722 </p><p>
674 Comparisons to singletons like None should always be done 723 Comparisons to singletons like None should always be done
675 with "is" or "is not", never the equality operators. 724 with "is" or "is not", never the equality operators.
676 </p><p> 725 </p><p>
677 Okay: if arg is not None: 726 Okay: if arg is not None:
678 E711: if arg != None: 727 E711: if arg != None:
687 <hr /><hr /> 736 <hr /><hr />
688 <a NAME="comparison_type" ID="comparison_type"></a> 737 <a NAME="comparison_type" ID="comparison_type"></a>
689 <h2>comparison_type</h2> 738 <h2>comparison_type</h2>
690 <b>comparison_type</b>(<i>logical_line</i>) 739 <b>comparison_type</b>(<i>logical_line</i>)
691 <p> 740 <p>
692 Object type comparisons should always use isinstance() instead of 741 Object type comparisons should always use isinstance().
693 comparing types directly. 742 </p><p>
743 Do not compare types directly.
694 </p><p> 744 </p><p>
695 Okay: if isinstance(obj, int): 745 Okay: if isinstance(obj, int):
696 E721: if type(obj) is type(1): 746 E721: if type(obj) is type(1):
697 </p><p> 747 </p><p>
698 When checking if an object is a string, keep in mind that it might be a 748 When checking if an object is a string, keep in mind that it might be a
706 <hr /><hr /> 756 <hr /><hr />
707 <a NAME="compound_statements" ID="compound_statements"></a> 757 <a NAME="compound_statements" ID="compound_statements"></a>
708 <h2>compound_statements</h2> 758 <h2>compound_statements</h2>
709 <b>compound_statements</b>(<i>logical_line</i>) 759 <b>compound_statements</b>(<i>logical_line</i>)
710 <p> 760 <p>
711 Compound statements (multiple statements on the same line) are 761 Compound statements (on the same line) are generally discouraged.
712 generally discouraged.
713 </p><p> 762 </p><p>
714 While sometimes it's okay to put an if/for/while with a small body 763 While sometimes it's okay to put an if/for/while with a small body
715 on the same line, never do this for multi-clause statements. Also 764 on the same line, never do this for multi-clause statements.
716 avoid folding such long lines! 765 Also avoid folding such long lines!
717 </p><p> 766 </p><p>
718 Okay: if foo == 'blah':\n do_blah_thing() 767 Okay: if foo == 'blah':\n do_blah_thing()
719 Okay: do_one() 768 Okay: do_one()
720 Okay: do_two() 769 Okay: do_two()
721 Okay: do_three() 770 Okay: do_three()
734 </p> 783 </p>
735 <div align="right"><a href="#top">Up</a></div> 784 <div align="right"><a href="#top">Up</a></div>
736 <hr /><hr /> 785 <hr /><hr />
737 <a NAME="continued_indentation" ID="continued_indentation"></a> 786 <a NAME="continued_indentation" ID="continued_indentation"></a>
738 <h2>continued_indentation</h2> 787 <h2>continued_indentation</h2>
739 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, noqa, verbose</i>) 788 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, indent_char, noqa, verbose</i>)
740 <p> 789 <p>
741 Continuation lines should align wrapped elements either vertically using 790 Continuation lines indentation.
742 Python's implicit line joining inside parentheses, brackets and braces, or 791 </p><p>
743 using a hanging indent. 792 Continuation lines should align wrapped elements either vertically
744 </p><p> 793 using Python's implicit line joining inside parentheses, brackets
745 When using a hanging indent the following considerations should be applied: 794 and braces, or using a hanging indent.
746 </p><p> 795 </p><p>
796 When using a hanging indent these considerations should be applied:
747 - there should be no arguments on the first line, and 797 - there should be no arguments on the first line, and
748 </p><p>
749 - further indentation should be used to clearly distinguish itself as a 798 - further indentation should be used to clearly distinguish itself as a
750 continuation line. 799 continuation line.
751 </p><p> 800 </p><p>
752 Okay: a = (\n) 801 Okay: a = (\n)
753 E123: a = (\n ) 802 E123: a = (\n )
755 Okay: a = (\n 42) 804 Okay: a = (\n 42)
756 E121: a = (\n 42) 805 E121: a = (\n 42)
757 E122: a = (\n42) 806 E122: a = (\n42)
758 E123: a = (\n 42\n ) 807 E123: a = (\n 42\n )
759 E124: a = (24,\n 42\n) 808 E124: a = (24,\n 42\n)
760 E125: if (a or\n b):\n pass 809 E125: if (\n b):\n pass
761 E126: a = (\n 42) 810 E126: a = (\n 42)
762 E127: a = (24,\n 42) 811 E127: a = (24,\n 42)
763 E128: a = (24,\n 42) 812 E128: a = (24,\n 42)
813 E129: if (a or\n b):\n pass
814 E131: a = (\n 42\n 24)
764 </p> 815 </p>
765 <div align="right"><a href="#top">Up</a></div> 816 <div align="right"><a href="#top">Up</a></div>
766 <hr /><hr /> 817 <hr /><hr />
767 <a NAME="expand_indent" ID="expand_indent"></a> 818 <a NAME="expand_indent" ID="expand_indent"></a>
768 <h2>expand_indent</h2> 819 <h2>expand_indent</h2>
769 <b>expand_indent</b>(<i>line</i>) 820 <b>expand_indent</b>(<i>line</i>)
770 <p> 821 <p>
771 Return the amount of indentation. 822 Return the amount of indentation.
823 </p><p>
772 Tabs are expanded to the next multiple of 8. 824 Tabs are expanded to the next multiple of 8.
773 </p><p> 825 </p><p>
774 >>> expand_indent(' ') 826 >>> expand_indent(' ')
775 4 827 4
776 >>> expand_indent('\t') 828 >>> expand_indent('\t')
777 8
778 >>> expand_indent(' \t')
779 8 829 8
780 >>> expand_indent(' \t') 830 >>> expand_indent(' \t')
781 8 831 8
782 >>> expand_indent(' \t') 832 >>> expand_indent(' \t')
783 16 833 16
786 <hr /><hr /> 836 <hr /><hr />
787 <a NAME="explicit_line_join" ID="explicit_line_join"></a> 837 <a NAME="explicit_line_join" ID="explicit_line_join"></a>
788 <h2>explicit_line_join</h2> 838 <h2>explicit_line_join</h2>
789 <b>explicit_line_join</b>(<i>logical_line, tokens</i>) 839 <b>explicit_line_join</b>(<i>logical_line, tokens</i>)
790 <p> 840 <p>
791 Avoid explicit line join between brackets. 841 Avoid explicit line join between brackets.
792 </p><p> 842 </p><p>
793 The preferred way of wrapping long lines is by using Python's implied line 843 The preferred way of wrapping long lines is by using Python's implied line
794 continuation inside parentheses, brackets and braces. Long lines can be 844 continuation inside parentheses, brackets and braces. Long lines can be
795 broken over multiple lines by wrapping expressions in parentheses. These 845 broken over multiple lines by wrapping expressions in parentheses. These
796 should be used in preference to using a backslash for line continuation. 846 should be used in preference to using a backslash for line continuation.
806 <hr /><hr /> 856 <hr /><hr />
807 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a> 857 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a>
808 <h2>extraneous_whitespace</h2> 858 <h2>extraneous_whitespace</h2>
809 <b>extraneous_whitespace</b>(<i>logical_line</i>) 859 <b>extraneous_whitespace</b>(<i>logical_line</i>)
810 <p> 860 <p>
811 Avoid extraneous whitespace in the following situations: 861 Avoid extraneous whitespace.
812 </p><p> 862 </p><p>
863 Avoid extraneous whitespace in these situations:
813 - Immediately inside parentheses, brackets or braces. 864 - Immediately inside parentheses, brackets or braces.
814 </p><p>
815 - Immediately before a comma, semicolon, or colon. 865 - Immediately before a comma, semicolon, or colon.
816 </p><p> 866 </p><p>
817 Okay: spam(ham[1], {eggs: 2}) 867 Okay: spam(ham[1], {eggs: 2})
818 E201: spam( ham[1], {eggs: 2}) 868 E201: spam( ham[1], {eggs: 2})
819 E201: spam(ham[ 1], {eggs: 2}) 869 E201: spam(ham[ 1], {eggs: 2})
830 <hr /><hr /> 880 <hr /><hr />
831 <a NAME="filename_match" ID="filename_match"></a> 881 <a NAME="filename_match" ID="filename_match"></a>
832 <h2>filename_match</h2> 882 <h2>filename_match</h2>
833 <b>filename_match</b>(<i>filename, patterns, default=True</i>) 883 <b>filename_match</b>(<i>filename, patterns, default=True</i>)
834 <p> 884 <p>
835 Check if patterns contains a pattern that matches filename. 885 Check if patterns contains a pattern that matches filename.
886 </p><p>
836 If patterns is unspecified, this always returns True. 887 If patterns is unspecified, this always returns True.
837 </p> 888 </p>
838 <div align="right"><a href="#top">Up</a></div> 889 <div align="right"><a href="#top">Up</a></div>
839 <hr /><hr /> 890 <hr /><hr />
840 <a NAME="get_parser" ID="get_parser"></a> 891 <a NAME="get_parser" ID="get_parser"></a>
845 <hr /><hr /> 896 <hr /><hr />
846 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a> 897 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a>
847 <h2>imports_on_separate_lines</h2> 898 <h2>imports_on_separate_lines</h2>
848 <b>imports_on_separate_lines</b>(<i>logical_line</i>) 899 <b>imports_on_separate_lines</b>(<i>logical_line</i>)
849 <p> 900 <p>
850 Imports should usually be on separate lines. 901 Imports should usually be on separate lines.
851 </p><p> 902 </p><p>
852 Okay: import os\nimport sys 903 Okay: import os\nimport sys
853 E401: import sys, os 904 E401: import sys, os
854 </p><p> 905 </p><p>
855 Okay: from subprocess import Popen, PIPE 906 Okay: from subprocess import Popen, PIPE
862 <hr /><hr /> 913 <hr /><hr />
863 <a NAME="indentation" ID="indentation"></a> 914 <a NAME="indentation" ID="indentation"></a>
864 <h2>indentation</h2> 915 <h2>indentation</h2>
865 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>) 916 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>)
866 <p> 917 <p>
867 Use 4 spaces per indentation level. 918 Use 4 spaces per indentation level.
868 </p><p> 919 </p><p>
869 For really old code that you don't want to mess up, you can continue to 920 For really old code that you don't want to mess up, you can continue to
870 use 8-space tabs. 921 use 8-space tabs.
871 </p><p> 922 </p><p>
872 Okay: a = 1 923 Okay: a = 1
883 <hr /><hr /> 934 <hr /><hr />
884 <a NAME="init_checks_registry" ID="init_checks_registry"></a> 935 <a NAME="init_checks_registry" ID="init_checks_registry"></a>
885 <h2>init_checks_registry</h2> 936 <h2>init_checks_registry</h2>
886 <b>init_checks_registry</b>(<i></i>) 937 <b>init_checks_registry</b>(<i></i>)
887 <p> 938 <p>
888 Register all globally visible functions where the first argument name 939 Register all globally visible functions.
889 is 'physical_line' or 'logical_line'. 940 </p><p>
941 The first argument name is either 'physical_line' or 'logical_line'.
890 </p> 942 </p>
891 <div align="right"><a href="#top">Up</a></div> 943 <div align="right"><a href="#top">Up</a></div>
892 <hr /><hr /> 944 <hr /><hr />
893 <a NAME="maximum_line_length" ID="maximum_line_length"></a> 945 <a NAME="maximum_line_length" ID="maximum_line_length"></a>
894 <h2>maximum_line_length</h2> 946 <h2>maximum_line_length</h2>
895 <b>maximum_line_length</b>(<i>physical_line, max_line_length</i>) 947 <b>maximum_line_length</b>(<i>physical_line, max_line_length, multiline</i>)
896 <p> 948 <p>
897 Limit all lines to a maximum of 79 characters. 949 Limit all lines to a maximum of 79 characters.
898 </p><p> 950 </p><p>
899 There are still many devices around that are limited to 80 character 951 There are still many devices around that are limited to 80 character
900 lines; plus, limiting windows to 80 characters makes it possible to have 952 lines; plus, limiting windows to 80 characters makes it possible to have
901 several windows side-by-side. The default wrapping on such devices looks 953 several windows side-by-side. The default wrapping on such devices looks
902 ugly. Therefore, please limit all lines to a maximum of 79 characters. 954 ugly. Therefore, please limit all lines to a maximum of 79 characters.
905 </p><p> 957 </p><p>
906 Reports error E501. 958 Reports error E501.
907 </p> 959 </p>
908 <div align="right"><a href="#top">Up</a></div> 960 <div align="right"><a href="#top">Up</a></div>
909 <hr /><hr /> 961 <hr /><hr />
910 <a NAME="missing_newline" ID="missing_newline"></a>
911 <h2>missing_newline</h2>
912 <b>missing_newline</b>(<i>physical_line</i>)
913 <p>
914 JCR: The last line should have a newline.
915 </p><p>
916 Reports warning W292.
917 </p>
918 <div align="right"><a href="#top">Up</a></div>
919 <hr /><hr />
920 <a NAME="missing_whitespace" ID="missing_whitespace"></a> 962 <a NAME="missing_whitespace" ID="missing_whitespace"></a>
921 <h2>missing_whitespace</h2> 963 <h2>missing_whitespace</h2>
922 <b>missing_whitespace</b>(<i>logical_line</i>) 964 <b>missing_whitespace</b>(<i>logical_line</i>)
923 <p> 965 <p>
924 JCR: Each comma, semicolon or colon should be followed by whitespace. 966 Each comma, semicolon or colon should be followed by whitespace.
925 </p><p> 967 </p><p>
926 Okay: [a, b] 968 Okay: [a, b]
927 Okay: (3,) 969 Okay: (3,)
928 Okay: a[1:4] 970 Okay: a[1:4]
929 Okay: a[:4] 971 Okay: a[:4]
937 <hr /><hr /> 979 <hr /><hr />
938 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a> 980 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a>
939 <h2>missing_whitespace_around_operator</h2> 981 <h2>missing_whitespace_around_operator</h2>
940 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>) 982 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>)
941 <p> 983 <p>
984 Surround operators with a single space on either side.
985 </p><p>
942 - Always surround these binary operators with a single space on 986 - Always surround these binary operators with a single space on
943 either side: assignment (=), augmented assignment (+=, -= etc.), 987 either side: assignment (=), augmented assignment (+=, -= etc.),
944 comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), 988 comparisons (==, <, >, !=, <=, >=, in, not in, is, is not),
945 Booleans (and, or, not). 989 Booleans (and, or, not).
946 </p><p> 990 </p><p>
947 - Use spaces around arithmetic operators. 991 - If operators with different priorities are used, consider adding
992 whitespace around the operators with the lowest priorities.
948 </p><p> 993 </p><p>
949 Okay: i = i + 1 994 Okay: i = i + 1
950 Okay: submitted += 1 995 Okay: submitted += 1
951 Okay: x = x * 2 - 1 996 Okay: x = x * 2 - 1
952 Okay: hypot2 = x * x + y * y 997 Okay: hypot2 = x * x + y * y
967 <hr /><hr /> 1012 <hr /><hr />
968 <a NAME="mute_string" ID="mute_string"></a> 1013 <a NAME="mute_string" ID="mute_string"></a>
969 <h2>mute_string</h2> 1014 <h2>mute_string</h2>
970 <b>mute_string</b>(<i>text</i>) 1015 <b>mute_string</b>(<i>text</i>)
971 <p> 1016 <p>
972 Replace contents with 'xxx' to prevent syntax matching. 1017 Replace contents with 'xxx' to prevent syntax matching.
973 </p><p> 1018 </p><p>
974 >>> mute_string('"abc"') 1019 >>> mute_string('"abc"')
975 '"xxx"' 1020 '"xxx"'
976 >>> mute_string("'''abc'''") 1021 >>> mute_string("'''abc'''")
977 "'''xxx'''" 1022 "'''xxx'''"
978 >>> mute_string("r'abc'") 1023 >>> mute_string("r'abc'")
979 "r'xxx'" 1024 "r'xxx'"
980 </p> 1025 </p>
981 <div align="right"><a href="#top">Up</a></div> 1026 <div align="right"><a href="#top">Up</a></div>
982 <hr /><hr /> 1027 <hr /><hr />
1028 <a NAME="normalize_paths" ID="normalize_paths"></a>
1029 <h2>normalize_paths</h2>
1030 <b>normalize_paths</b>(<i>value, parent=os.curdir</i>)
1031 <p>
1032 Parse a comma-separated list of paths.
1033 </p><p>
1034 Return a list of absolute paths.
1035 </p>
1036 <div align="right"><a href="#top">Up</a></div>
1037 <hr /><hr />
983 <a NAME="parse_udiff" ID="parse_udiff"></a> 1038 <a NAME="parse_udiff" ID="parse_udiff"></a>
984 <h2>parse_udiff</h2> 1039 <h2>parse_udiff</h2>
985 <b>parse_udiff</b>(<i>diff, patterns=None, parent='.'</i>) 1040 <b>parse_udiff</b>(<i>diff, patterns=None, parent='.'</i>)
986 <p> 1041 <p>
987 Return a dictionary of matching lines. 1042 Return a dictionary of matching lines.
998 <hr /><hr /> 1053 <hr /><hr />
999 <a NAME="python_3000_backticks" ID="python_3000_backticks"></a> 1054 <a NAME="python_3000_backticks" ID="python_3000_backticks"></a>
1000 <h2>python_3000_backticks</h2> 1055 <h2>python_3000_backticks</h2>
1001 <b>python_3000_backticks</b>(<i>logical_line</i>) 1056 <b>python_3000_backticks</b>(<i>logical_line</i>)
1002 <p> 1057 <p>
1003 Backticks are removed in Python 3. 1058 Backticks are removed in Python 3: use repr() instead.
1004 Use repr() instead.
1005 </p><p> 1059 </p><p>
1006 Okay: val = repr(1 + 2) 1060 Okay: val = repr(1 + 2)
1007 W604: val = `1 + 2` 1061 W604: val = `1 + 2`
1008 </p> 1062 </p>
1009 <div align="right"><a href="#top">Up</a></div> 1063 <div align="right"><a href="#top">Up</a></div>
1010 <hr /><hr /> 1064 <hr /><hr />
1011 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a> 1065 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a>
1012 <h2>python_3000_has_key</h2> 1066 <h2>python_3000_has_key</h2>
1013 <b>python_3000_has_key</b>(<i>logical_line</i>) 1067 <b>python_3000_has_key</b>(<i>logical_line, noqa</i>)
1014 <p> 1068 <p>
1015 The {}.has_key() method is removed in the Python 3. 1069 The {}.has_key() method is removed in Python 3: use the 'in' operator.
1016 Use the 'in' operation instead.
1017 </p><p> 1070 </p><p>
1018 Okay: if "alph" in d:\n print d["alph"] 1071 Okay: if "alph" in d:\n print d["alph"]
1019 W601: assert d.has_key('alph') 1072 W601: assert d.has_key('alph')
1020 </p> 1073 </p>
1021 <div align="right"><a href="#top">Up</a></div> 1074 <div align="right"><a href="#top">Up</a></div>
1022 <hr /><hr /> 1075 <hr /><hr />
1023 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a> 1076 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a>
1024 <h2>python_3000_not_equal</h2> 1077 <h2>python_3000_not_equal</h2>
1025 <b>python_3000_not_equal</b>(<i>logical_line</i>) 1078 <b>python_3000_not_equal</b>(<i>logical_line</i>)
1026 <p> 1079 <p>
1027 != can also be written <>, but this is an obsolete usage kept for 1080 New code should always use != instead of <>.
1028 backwards compatibility only. New code should always use !=. 1081 </p><p>
1029 The older syntax is removed in Python 3. 1082 The older syntax is removed in Python 3.
1030 </p><p> 1083 </p><p>
1031 Okay: if a != 'no': 1084 Okay: if a != 'no':
1032 W603: if a <> 'no': 1085 W603: if a <> 'no':
1033 </p> 1086 </p>
1035 <hr /><hr /> 1088 <hr /><hr />
1036 <a NAME="python_3000_raise_comma" ID="python_3000_raise_comma"></a> 1089 <a NAME="python_3000_raise_comma" ID="python_3000_raise_comma"></a>
1037 <h2>python_3000_raise_comma</h2> 1090 <h2>python_3000_raise_comma</h2>
1038 <b>python_3000_raise_comma</b>(<i>logical_line</i>) 1091 <b>python_3000_raise_comma</b>(<i>logical_line</i>)
1039 <p> 1092 <p>
1040 When raising an exception, use "raise ValueError('message')" 1093 When raising an exception, use "raise ValueError('message')".
1041 instead of the older form "raise ValueError, 'message'". 1094 </p><p>
1042 </p><p> 1095 The older form is removed in Python 3.
1043 The paren-using form is preferred because when the exception arguments
1044 are long or include string formatting, you don't need to use line
1045 continuation characters thanks to the containing parentheses. The older
1046 form is removed in Python 3.
1047 </p><p> 1096 </p><p>
1048 Okay: raise DummyError("Message") 1097 Okay: raise DummyError("Message")
1049 W602: raise DummyError, "Message" 1098 W602: raise DummyError, "Message"
1050 </p> 1099 </p>
1051 <div align="right"><a href="#top">Up</a></div> 1100 <div align="right"><a href="#top">Up</a></div>
1059 <div align="right"><a href="#top">Up</a></div> 1108 <div align="right"><a href="#top">Up</a></div>
1060 <hr /><hr /> 1109 <hr /><hr />
1061 <a NAME="readlines" ID="readlines"></a> 1110 <a NAME="readlines" ID="readlines"></a>
1062 <h2>readlines</h2> 1111 <h2>readlines</h2>
1063 <b>readlines</b>(<i>filename</i>) 1112 <b>readlines</b>(<i>filename</i>)
1064 1113 <p>
1114 Read the source code.
1115 </p>
1065 <div align="right"><a href="#top">Up</a></div> 1116 <div align="right"><a href="#top">Up</a></div>
1066 <hr /><hr /> 1117 <hr /><hr />
1067 <a NAME="readlines_1" ID="readlines_1"></a> 1118 <a NAME="readlines_1" ID="readlines_1"></a>
1068 <h2>readlines</h2> 1119 <h2>readlines</h2>
1069 <b>readlines</b>(<i>filename</i>) 1120 <b>readlines</b>(<i>filename</i>)
1070 1121 <p>
1122 Read the source code.
1123 </p>
1071 <div align="right"><a href="#top">Up</a></div> 1124 <div align="right"><a href="#top">Up</a></div>
1072 <hr /><hr /> 1125 <hr /><hr />
1073 <a NAME="register_check" ID="register_check"></a> 1126 <a NAME="register_check" ID="register_check"></a>
1074 <h2>register_check</h2> 1127 <h2>register_check</h2>
1075 <b>register_check</b>(<i>check, codes=None</i>) 1128 <b>register_check</b>(<i>check, codes=None</i>)
1076 <p> 1129 <p>
1077 Register a new check object. 1130 Register a new check object.
1078 </p> 1131 </p>
1079 <div align="right"><a href="#top">Up</a></div> 1132 <div align="right"><a href="#top">Up</a></div>
1080 <hr /><hr /> 1133 <hr /><hr />
1081 <a NAME="stdin_get_value" ID="stdin_get_value"></a> 1134 <a NAME="stdin_get_value" ID="stdin_get_value"></a>
1082 <h2>stdin_get_value</h2> 1135 <h2>stdin_get_value</h2>
1086 <hr /><hr /> 1139 <hr /><hr />
1087 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a> 1140 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a>
1088 <h2>tabs_obsolete</h2> 1141 <h2>tabs_obsolete</h2>
1089 <b>tabs_obsolete</b>(<i>physical_line</i>) 1142 <b>tabs_obsolete</b>(<i>physical_line</i>)
1090 <p> 1143 <p>
1091 For new projects, spaces-only are strongly recommended over tabs. Most 1144 For new projects, spaces-only are strongly recommended over tabs.
1092 editors have features that make this easy to do.
1093 </p><p> 1145 </p><p>
1094 Okay: if True:\n return 1146 Okay: if True:\n return
1095 W191: if True:\n\treturn 1147 W191: if True:\n\treturn
1096 </p> 1148 </p>
1097 <div align="right"><a href="#top">Up</a></div> 1149 <div align="right"><a href="#top">Up</a></div>
1098 <hr /><hr /> 1150 <hr /><hr />
1099 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a> 1151 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a>
1100 <h2>tabs_or_spaces</h2> 1152 <h2>tabs_or_spaces</h2>
1101 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>) 1153 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>)
1102 <p> 1154 <p>
1103 Never mix tabs and spaces. 1155 Never mix tabs and spaces.
1104 </p><p> 1156 </p><p>
1105 The most popular way of indenting Python is with spaces only. The 1157 The most popular way of indenting Python is with spaces only. The
1106 second-most popular way is with tabs only. Code indented with a mixture 1158 second-most popular way is with tabs only. Code indented with a mixture
1107 of tabs and spaces should be converted to using spaces exclusively. When 1159 of tabs and spaces should be converted to using spaces exclusively. When
1108 invoking the Python command line interpreter with the -t option, it issues 1160 invoking the Python command line interpreter with the -t option, it issues
1114 </p> 1166 </p>
1115 <div align="right"><a href="#top">Up</a></div> 1167 <div align="right"><a href="#top">Up</a></div>
1116 <hr /><hr /> 1168 <hr /><hr />
1117 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a> 1169 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a>
1118 <h2>trailing_blank_lines</h2> 1170 <h2>trailing_blank_lines</h2>
1119 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>) 1171 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number, total_lines</i>)
1120 <p> 1172 <p>
1121 JCR: Trailing blank lines are superfluous. 1173 Trailing blank lines are superfluous.
1122 </p><p> 1174 </p><p>
1123 Okay: spam(1) 1175 Okay: spam(1)
1124 W391: spam(1)\n 1176 W391: spam(1)\n
1177 </p><p>
1178 However the last line should end with a new line (warning W292).
1125 </p> 1179 </p>
1126 <div align="right"><a href="#top">Up</a></div> 1180 <div align="right"><a href="#top">Up</a></div>
1127 <hr /><hr /> 1181 <hr /><hr />
1128 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a> 1182 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a>
1129 <h2>trailing_whitespace</h2> 1183 <h2>trailing_whitespace</h2>
1130 <b>trailing_whitespace</b>(<i>physical_line</i>) 1184 <b>trailing_whitespace</b>(<i>physical_line</i>)
1131 <p> 1185 <p>
1132 JCR: Trailing whitespace is superfluous. 1186 Trailing whitespace is superfluous.
1133 FBM: Except when it occurs as part of a blank line (i.e. the line is
1134 nothing but whitespace). According to Python docs[1] a line with only
1135 whitespace is considered a blank line, and is to be ignored. However,
1136 matching a blank line to its indentation level avoids mistakenly
1137 terminating a multi-line statement (e.g. class declaration) when
1138 pasting code into the standard Python interpreter.
1139 </p><p>
1140 [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines
1141 </p><p> 1187 </p><p>
1142 The warning returned varies on whether the line itself is blank, for easier 1188 The warning returned varies on whether the line itself is blank, for easier
1143 filtering for those who want to indent their blank lines. 1189 filtering for those who want to indent their blank lines.
1144 </p><p> 1190 </p><p>
1145 Okay: spam(1)\n# 1191 Okay: spam(1)\n#
1150 <hr /><hr /> 1196 <hr /><hr />
1151 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a> 1197 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a>
1152 <h2>whitespace_around_comma</h2> 1198 <h2>whitespace_around_comma</h2>
1153 <b>whitespace_around_comma</b>(<i>logical_line</i>) 1199 <b>whitespace_around_comma</b>(<i>logical_line</i>)
1154 <p> 1200 <p>
1155 Avoid extraneous whitespace in the following situations: 1201 Avoid extraneous whitespace after a comma or a colon.
1156 </p><p> 1202 </p><p>
1157 - More than one space around an assignment (or other) operator to
1158 align it with another.
1159 </p><p>
1160 JCR: This should also be applied around comma etc.
1161 Note: these checks are disabled by default 1203 Note: these checks are disabled by default
1162 </p><p> 1204 </p><p>
1163 Okay: a = (1, 2) 1205 Okay: a = (1, 2)
1164 E241: a = (1, 2) 1206 E241: a = (1, 2)
1165 E242: a = (1,\t2) 1207 E242: a = (1,\t2)
1168 <hr /><hr /> 1210 <hr /><hr />
1169 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a> 1211 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a>
1170 <h2>whitespace_around_keywords</h2> 1212 <h2>whitespace_around_keywords</h2>
1171 <b>whitespace_around_keywords</b>(<i>logical_line</i>) 1213 <b>whitespace_around_keywords</b>(<i>logical_line</i>)
1172 <p> 1214 <p>
1173 Avoid extraneous whitespace around keywords. 1215 Avoid extraneous whitespace around keywords.
1174 </p><p> 1216 </p><p>
1175 Okay: True and False 1217 Okay: True and False
1176 E271: True and False 1218 E271: True and False
1177 E272: True and False 1219 E272: True and False
1178 E273: True and\tFalse 1220 E273: True and\tFalse
1182 <hr /><hr /> 1224 <hr /><hr />
1183 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a> 1225 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a>
1184 <h2>whitespace_around_named_parameter_equals</h2> 1226 <h2>whitespace_around_named_parameter_equals</h2>
1185 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>) 1227 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>)
1186 <p> 1228 <p>
1229 Don't use spaces around the '=' sign in function arguments.
1230 </p><p>
1187 Don't use spaces around the '=' sign when used to indicate a 1231 Don't use spaces around the '=' sign when used to indicate a
1188 keyword argument or a default parameter value. 1232 keyword argument or a default parameter value.
1189 </p><p> 1233 </p><p>
1190 Okay: def complex(real, imag=0.0): 1234 Okay: def complex(real, imag=0.0):
1191 Okay: return magic(r=real, i=imag) 1235 Okay: return magic(r=real, i=imag)
1201 <hr /><hr /> 1245 <hr /><hr />
1202 <a NAME="whitespace_around_operator" ID="whitespace_around_operator"></a> 1246 <a NAME="whitespace_around_operator" ID="whitespace_around_operator"></a>
1203 <h2>whitespace_around_operator</h2> 1247 <h2>whitespace_around_operator</h2>
1204 <b>whitespace_around_operator</b>(<i>logical_line</i>) 1248 <b>whitespace_around_operator</b>(<i>logical_line</i>)
1205 <p> 1249 <p>
1206 Avoid extraneous whitespace in the following situations: 1250 Avoid extraneous whitespace around an operator.
1207 </p><p>
1208 - More than one space around an assignment (or other) operator to
1209 align it with another.
1210 </p><p> 1251 </p><p>
1211 Okay: a = 12 + 3 1252 Okay: a = 12 + 3
1212 E221: a = 4 + 5 1253 E221: a = 4 + 5
1213 E222: a = 4 + 5 1254 E222: a = 4 + 5
1214 E223: a = 4\t+ 5 1255 E223: a = 4\t+ 5
1215 E224: a = 4 +\t5 1256 E224: a = 4 +\t5
1216 </p> 1257 </p>
1217 <div align="right"><a href="#top">Up</a></div> 1258 <div align="right"><a href="#top">Up</a></div>
1218 <hr /><hr /> 1259 <hr /><hr />
1219 <a NAME="whitespace_before_inline_comment" ID="whitespace_before_inline_comment"></a> 1260 <a NAME="whitespace_before_comment" ID="whitespace_before_comment"></a>
1220 <h2>whitespace_before_inline_comment</h2> 1261 <h2>whitespace_before_comment</h2>
1221 <b>whitespace_before_inline_comment</b>(<i>logical_line, tokens</i>) 1262 <b>whitespace_before_comment</b>(<i>logical_line, tokens</i>)
1222 <p> 1263 <p>
1223 Separate inline comments by at least two spaces. 1264 Separate inline comments by at least two spaces.
1224 </p><p> 1265 </p><p>
1225 An inline comment is a comment on the same line as a statement. Inline 1266 An inline comment is a comment on the same line as a statement. Inline
1226 comments should be separated by at least two spaces from the statement. 1267 comments should be separated by at least two spaces from the statement.
1227 They should start with a # and a single space. 1268 They should start with a # and a single space.
1228 </p><p> 1269 </p><p>
1270 Each line of a block comment starts with a # and a single space
1271 (unless it is indented text inside the comment).
1272 </p><p>
1229 Okay: x = x + 1 # Increment x 1273 Okay: x = x + 1 # Increment x
1230 Okay: x = x + 1 # Increment x 1274 Okay: x = x + 1 # Increment x
1275 Okay: # Block comment
1231 E261: x = x + 1 # Increment x 1276 E261: x = x + 1 # Increment x
1232 E262: x = x + 1 #Increment x 1277 E262: x = x + 1 #Increment x
1233 E262: x = x + 1 # Increment x 1278 E262: x = x + 1 # Increment x
1279 E265: #Block comment
1234 </p> 1280 </p>
1235 <div align="right"><a href="#top">Up</a></div> 1281 <div align="right"><a href="#top">Up</a></div>
1236 <hr /><hr /> 1282 <hr /><hr />
1237 <a NAME="whitespace_before_parameters" ID="whitespace_before_parameters"></a> 1283 <a NAME="whitespace_before_parameters" ID="whitespace_before_parameters"></a>
1238 <h2>whitespace_before_parameters</h2> 1284 <h2>whitespace_before_parameters</h2>
1239 <b>whitespace_before_parameters</b>(<i>logical_line, tokens</i>) 1285 <b>whitespace_before_parameters</b>(<i>logical_line, tokens</i>)
1240 <p> 1286 <p>
1287 Avoid extraneous whitespace.
1288 </p><p>
1241 Avoid extraneous whitespace in the following situations: 1289 Avoid extraneous whitespace in the following situations:
1242 </p><p> 1290 - before the open parenthesis that starts the argument list of a
1243 - Immediately before the open parenthesis that starts the argument 1291 function call.
1244 list of a function call. 1292 - before the open parenthesis that starts an indexing or slicing.
1245 </p><p>
1246 - Immediately before the open parenthesis that starts an indexing or
1247 slicing.
1248 </p><p> 1293 </p><p>
1249 Okay: spam(1) 1294 Okay: spam(1)
1250 E211: spam (1) 1295 E211: spam (1)
1251 </p><p> 1296 </p><p>
1252 Okay: dict['key'] = list[index] 1297 Okay: dict['key'] = list[index]

eric ide

mercurial