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

branch
5_3_x
changeset 2970
e9f971b4b3c5
parent 2374
f78ee0e8f96c
equal deleted inserted replaced
2943:12ff9a078e11 2970:e9f971b4b3c5
37 <tr> 37 <tr>
38 <td><a href="#_main">_main</a></td> 38 <td><a href="#_main">_main</a></td>
39 <td>Parse options and run checks on Python source.</td> 39 <td>Parse options and run checks on Python source.</td>
40 </tr><tr> 40 </tr><tr>
41 <td><a href="#blank_lines">blank_lines</a></td> 41 <td><a href="#blank_lines">blank_lines</a></td>
42 <td></td> 42 <td>Separate top-level function and class definitions with two blank lines.</td>
43 </tr><tr> 43 </tr><tr>
44 <td><a href="#compound_statements">compound_statements</a></td> 44 <td><a href="#compound_statements">compound_statements</a></td>
45 <td></td> 45 <td>Compound statements (multiple statements on the same line) are generally discouraged.</td>
46 </tr><tr> 46 </tr><tr>
47 <td><a href="#excluded">excluded</a></td> 47 <td><a href="#excluded">excluded</a></td>
48 <td>Check if options.exclude contains a pattern that matches filename.</td> 48 <td>Check if options.exclude contains a pattern that matches filename.</td>
49 </tr><tr> 49 </tr><tr>
50 <td><a href="#expand_indent">expand_indent</a></td> 50 <td><a href="#expand_indent">expand_indent</a></td>
76 </tr><tr> 76 </tr><tr>
77 <td><a href="#ignore_code">ignore_code</a></td> 77 <td><a href="#ignore_code">ignore_code</a></td>
78 <td>Check if options.ignore contains a prefix of the error code.</td> 78 <td>Check if options.ignore contains a prefix of the error code.</td>
79 </tr><tr> 79 </tr><tr>
80 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td> 80 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td>
81 <td></td> 81 <td>Imports should usually be on separate lines.</td>
82 </tr><tr> 82 </tr><tr>
83 <td><a href="#indentation">indentation</a></td> 83 <td><a href="#indentation">indentation</a></td>
84 <td></td> 84 <td>Use 4 spaces per indentation level.</td>
85 </tr><tr> 85 </tr><tr>
86 <td><a href="#input_dir">input_dir</a></td> 86 <td><a href="#input_dir">input_dir</a></td>
87 <td>Check all Python source files in this directory and all subdirectories.</td> 87 <td>Check all Python source files in this directory and all subdirectories.</td>
88 </tr><tr> 88 </tr><tr>
89 <td><a href="#input_file">input_file</a></td> 89 <td><a href="#input_file">input_file</a></td>
100 </tr><tr> 100 </tr><tr>
101 <td><a href="#missing_whitespace">missing_whitespace</a></td> 101 <td><a href="#missing_whitespace">missing_whitespace</a></td>
102 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td> 102 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td>
103 </tr><tr> 103 </tr><tr>
104 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td> 104 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td>
105 <td></td> 105 <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>
106 </tr><tr> 106 </tr><tr>
107 <td><a href="#mute_string">mute_string</a></td> 107 <td><a href="#mute_string">mute_string</a></td>
108 <td>Replace contents with 'xxx' to prevent syntax matching.</td> 108 <td>Replace contents with 'xxx' to prevent syntax matching.</td>
109 </tr><tr> 109 </tr><tr>
110 <td><a href="#print_benchmark">print_benchmark</a></td> 110 <td><a href="#print_benchmark">print_benchmark</a></td>
142 </tr><tr> 142 </tr><tr>
143 <td><a href="#selftest">selftest</a></td> 143 <td><a href="#selftest">selftest</a></td>
144 <td>Test all check functions with test cases in docstrings.</td> 144 <td>Test all check functions with test cases in docstrings.</td>
145 </tr><tr> 145 </tr><tr>
146 <td><a href="#tabs_obsolete">tabs_obsolete</a></td> 146 <td><a href="#tabs_obsolete">tabs_obsolete</a></td>
147 <td></td> 147 <td>For new projects, spaces-only are strongly recommended over tabs.</td>
148 </tr><tr> 148 </tr><tr>
149 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td> 149 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td>
150 <td></td> 150 <td>Never mix tabs and spaces.</td>
151 </tr><tr> 151 </tr><tr>
152 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td> 152 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td>
153 <td></td> 153 <td>JCR: Trailing blank lines are superfluous.</td>
154 </tr><tr> 154 </tr><tr>
155 <td><a href="#trailing_whitespace">trailing_whitespace</a></td> 155 <td><a href="#trailing_whitespace">trailing_whitespace</a></td>
156 <td></td> 156 <td>JCR: Trailing whitespace is superfluous.</td>
157 </tr><tr> 157 </tr><tr>
158 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td> 158 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td>
159 <td>Avoid extraneous whitespace in the following situations:</td> 159 <td>Avoid extraneous whitespace in the following situations:</td>
160 </tr><tr> 160 </tr><tr>
161 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td> 161 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td>
278 <div align="right"><a href="#top">Up</a></div> 278 <div align="right"><a href="#top">Up</a></div>
279 <hr /><hr /> 279 <hr /><hr />
280 <a NAME="blank_lines" ID="blank_lines"></a> 280 <a NAME="blank_lines" ID="blank_lines"></a>
281 <h2>blank_lines</h2> 281 <h2>blank_lines</h2>
282 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level, blank_lines_before_comment</i>) 282 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level, blank_lines_before_comment</i>)
283 283 <p>
284 Separate top-level function and class definitions with two blank lines.
285 </p><p>
286 Method definitions inside a class are separated by a single blank line.
287 </p><p>
288 Extra blank lines may be used (sparingly) to separate groups of related
289 functions. Blank lines may be omitted between a bunch of related
290 one-liners (e.g. a set of dummy implementations).
291 </p><p>
292 Use blank lines in functions, sparingly, to indicate logical sections.
293 </p><p>
294 Okay: def a():\n pass\n\n\ndef b():\n pass
295 Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass
296 </p><p>
297 E301: class Foo:\n b = 0\n def bar():\n pass
298 E302: def a():\n pass\n\ndef b(n):\n pass
299 E303: def a():\n pass\n\n\n\ndef b(n):\n pass
300 E303: def a():\n\n\n\n pass
301 E304: @decorator\n\ndef a():\n pass
302 </p>
284 <div align="right"><a href="#top">Up</a></div> 303 <div align="right"><a href="#top">Up</a></div>
285 <hr /><hr /> 304 <hr /><hr />
286 <a NAME="compound_statements" ID="compound_statements"></a> 305 <a NAME="compound_statements" ID="compound_statements"></a>
287 <h2>compound_statements</h2> 306 <h2>compound_statements</h2>
288 <b>compound_statements</b>(<i>logical_line</i>) 307 <b>compound_statements</b>(<i>logical_line</i>)
289 308 <p>
309 Compound statements (multiple statements on the same line) are
310 generally discouraged.
311 </p><p>
312 While sometimes it's okay to put an if/for/while with a small body
313 on the same line, never do this for multi-clause statements. Also
314 avoid folding such long lines!
315 </p><p>
316 Okay: if foo == 'blah':\n do_blah_thing()
317 Okay: do_one()
318 Okay: do_two()
319 Okay: do_three()
320 </p><p>
321 E701: if foo == 'blah': do_blah_thing()
322 E701: for x in lst: total += x
323 E701: while t < 10: t = delay()
324 E701: if foo == 'blah': do_blah_thing()
325 E701: else: do_non_blah_thing()
326 E701: try: something()
327 E701: finally: cleanup()
328 E701: if foo == 'blah': one(); two(); three()
329 </p><p>
330 E702: do_one(); do_two(); do_three()
331 </p>
290 <div align="right"><a href="#top">Up</a></div> 332 <div align="right"><a href="#top">Up</a></div>
291 <hr /><hr /> 333 <hr /><hr />
292 <a NAME="excluded" ID="excluded"></a> 334 <a NAME="excluded" ID="excluded"></a>
293 <h2>excluded</h2> 335 <h2>excluded</h2>
294 <b>excluded</b>(<i>filename</i>) 336 <b>excluded</b>(<i>filename</i>)
427 <div align="right"><a href="#top">Up</a></div> 469 <div align="right"><a href="#top">Up</a></div>
428 <hr /><hr /> 470 <hr /><hr />
429 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a> 471 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a>
430 <h2>imports_on_separate_lines</h2> 472 <h2>imports_on_separate_lines</h2>
431 <b>imports_on_separate_lines</b>(<i>logical_line</i>) 473 <b>imports_on_separate_lines</b>(<i>logical_line</i>)
432 474 <p>
475 Imports should usually be on separate lines.
476 </p><p>
477 Okay: import os\nimport sys
478 E401: import sys, os
479 </p><p>
480 Okay: from subprocess import Popen, PIPE
481 Okay: from myclas import MyClass
482 Okay: from foo.bar.yourclass import YourClass
483 Okay: import myclass
484 Okay: import foo.bar.yourclass
485 </p>
433 <div align="right"><a href="#top">Up</a></div> 486 <div align="right"><a href="#top">Up</a></div>
434 <hr /><hr /> 487 <hr /><hr />
435 <a NAME="indentation" ID="indentation"></a> 488 <a NAME="indentation" ID="indentation"></a>
436 <h2>indentation</h2> 489 <h2>indentation</h2>
437 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>) 490 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>)
438 491 <p>
492 Use 4 spaces per indentation level.
493 </p><p>
494 For really old code that you don't want to mess up, you can continue to
495 use 8-space tabs.
496 </p><p>
497 Okay: a = 1
498 Okay: if a == 0:\n a = 1
499 E111: a = 1
500 </p><p>
501 Okay: for item in items:\n pass
502 E112: for item in items:\npass
503 </p><p>
504 Okay: a = 1\nb = 2
505 E113: a = 1\n b = 2
506 </p>
439 <div align="right"><a href="#top">Up</a></div> 507 <div align="right"><a href="#top">Up</a></div>
440 <hr /><hr /> 508 <hr /><hr />
441 <a NAME="input_dir" ID="input_dir"></a> 509 <a NAME="input_dir" ID="input_dir"></a>
442 <h2>input_dir</h2> 510 <h2>input_dir</h2>
443 <b>input_dir</b>(<i>dirname, runner=None</i>) 511 <b>input_dir</b>(<i>dirname, runner=None</i>)
503 <div align="right"><a href="#top">Up</a></div> 571 <div align="right"><a href="#top">Up</a></div>
504 <hr /><hr /> 572 <hr /><hr />
505 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a> 573 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a>
506 <h2>missing_whitespace_around_operator</h2> 574 <h2>missing_whitespace_around_operator</h2>
507 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>) 575 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>)
508 576 <p>
577 - Always surround these binary operators with a single space on
578 either side: assignment (=), augmented assignment (+=, -= etc.),
579 comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
580 Booleans (and, or, not).
581 </p><p>
582 - Use spaces around arithmetic operators.
583 </p><p>
584 Okay: i = i + 1
585 Okay: submitted += 1
586 Okay: x = x * 2 - 1
587 Okay: hypot2 = x * x + y * y
588 Okay: c = (a + b) * (a - b)
589 Okay: foo(bar, key='word', *args, **kwargs)
590 Okay: baz(**kwargs)
591 Okay: negative = -1
592 Okay: spam(-1)
593 Okay: alpha[:-i]
594 Okay: if not -5 < x < +5:\n pass
595 Okay: lambda *args, **kw: (args, kw)
596 </p><p>
597 E225: i=i+1
598 E225: submitted +=1
599 E225: x = x*2 - 1
600 E225: hypot2 = x*x + y*y
601 E225: c = (a+b) * (a-b)
602 E225: c = alpha -4
603 E225: z = x **y
604 </p>
509 <div align="right"><a href="#top">Up</a></div> 605 <div align="right"><a href="#top">Up</a></div>
510 <hr /><hr /> 606 <hr /><hr />
511 <a NAME="mute_string" ID="mute_string"></a> 607 <a NAME="mute_string" ID="mute_string"></a>
512 <h2>mute_string</h2> 608 <h2>mute_string</h2>
513 <b>mute_string</b>(<i>text</i>) 609 <b>mute_string</b>(<i>text</i>)
641 <div align="right"><a href="#top">Up</a></div> 737 <div align="right"><a href="#top">Up</a></div>
642 <hr /><hr /> 738 <hr /><hr />
643 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a> 739 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a>
644 <h2>tabs_obsolete</h2> 740 <h2>tabs_obsolete</h2>
645 <b>tabs_obsolete</b>(<i>physical_line</i>) 741 <b>tabs_obsolete</b>(<i>physical_line</i>)
646 742 <p>
743 For new projects, spaces-only are strongly recommended over tabs. Most
744 editors have features that make this easy to do.
745 </p><p>
746 Okay: if True:\n return
747 W191: if True:\n\treturn
748 </p>
647 <div align="right"><a href="#top">Up</a></div> 749 <div align="right"><a href="#top">Up</a></div>
648 <hr /><hr /> 750 <hr /><hr />
649 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a> 751 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a>
650 <h2>tabs_or_spaces</h2> 752 <h2>tabs_or_spaces</h2>
651 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>) 753 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>)
652 754 <p>
755 Never mix tabs and spaces.
756 </p><p>
757 The most popular way of indenting Python is with spaces only. The
758 second-most popular way is with tabs only. Code indented with a mixture
759 of tabs and spaces should be converted to using spaces exclusively. When
760 invoking the Python command line interpreter with the -t option, it issues
761 warnings about code that illegally mixes tabs and spaces. When using -tt
762 these warnings become errors. These options are highly recommended!
763 </p><p>
764 Okay: if a == 0:\n a = 1\n b = 1
765 E101: if a == 0:\n a = 1\n\tb = 1
766 </p>
653 <div align="right"><a href="#top">Up</a></div> 767 <div align="right"><a href="#top">Up</a></div>
654 <hr /><hr /> 768 <hr /><hr />
655 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a> 769 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a>
656 <h2>trailing_blank_lines</h2> 770 <h2>trailing_blank_lines</h2>
657 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>) 771 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>)
658 772 <p>
773 JCR: Trailing blank lines are superfluous.
774 </p><p>
775 Okay: spam(1)
776 W391: spam(1)\n
777 </p>
659 <div align="right"><a href="#top">Up</a></div> 778 <div align="right"><a href="#top">Up</a></div>
660 <hr /><hr /> 779 <hr /><hr />
661 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a> 780 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a>
662 <h2>trailing_whitespace</h2> 781 <h2>trailing_whitespace</h2>
663 <b>trailing_whitespace</b>(<i>physical_line</i>) 782 <b>trailing_whitespace</b>(<i>physical_line</i>)
664 783 <p>
784 JCR: Trailing whitespace is superfluous.
785 FBM: Except when it occurs as part of a blank line (i.e. the line is
786 nothing but whitespace). According to Python docs[1] a line with only
787 whitespace is considered a blank line, and is to be ignored. However,
788 matching a blank line to its indentation level avoids mistakenly
789 terminating a multi-line statement (e.g. class declaration) when
790 pasting code into the standard Python interpreter.
791 </p><p>
792 [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines
793 </p><p>
794 The warning returned varies on whether the line itself is blank, for easier
795 filtering for those who want to indent their blank lines.
796 </p><p>
797 Okay: spam(1)
798 W291: spam(1)\s
799 W293: class Foo(object):\n \n bang = 12
800 </p>
665 <div align="right"><a href="#top">Up</a></div> 801 <div align="right"><a href="#top">Up</a></div>
666 <hr /><hr /> 802 <hr /><hr />
667 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a> 803 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a>
668 <h2>whitespace_around_comma</h2> 804 <h2>whitespace_around_comma</h2>
669 <b>whitespace_around_comma</b>(<i>logical_line</i>) 805 <b>whitespace_around_comma</b>(<i>logical_line</i>)

eric ide

mercurial