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