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

changeset 2923
01ac1f364b38
parent 2867
eb325d7f7335
equal deleted inserted replaced
2922:16905f0f48be 2923:01ac1f364b38
55 </tr><tr> 55 </tr><tr>
56 <td><a href="#_main">_main</a></td> 56 <td><a href="#_main">_main</a></td>
57 <td>Parse options and run checks on Python source.</td> 57 <td>Parse options and run checks on Python source.</td>
58 </tr><tr> 58 </tr><tr>
59 <td><a href="#blank_lines">blank_lines</a></td> 59 <td><a href="#blank_lines">blank_lines</a></td>
60 <td></td> 60 <td>Separate top-level function and class definitions with two blank lines.</td>
61 </tr><tr> 61 </tr><tr>
62 <td><a href="#comparison_to_singleton">comparison_to_singleton</a></td> 62 <td><a href="#comparison_to_singleton">comparison_to_singleton</a></td>
63 <td>Comparisons to singletons like None should always be done with "is" or "is not", never the equality operators.</td> 63 <td>Comparisons to singletons like None should always be done with "is" or "is not", never the equality operators.</td>
64 </tr><tr> 64 </tr><tr>
65 <td><a href="#comparison_type">comparison_type</a></td> 65 <td><a href="#comparison_type">comparison_type</a></td>
66 <td>Object type comparisons should always use isinstance() instead of comparing types directly.</td> 66 <td>Object type comparisons should always use isinstance() instead of comparing types directly.</td>
67 </tr><tr> 67 </tr><tr>
68 <td><a href="#compound_statements">compound_statements</a></td> 68 <td><a href="#compound_statements">compound_statements</a></td>
69 <td></td> 69 <td>Compound statements (multiple statements on the same line) are generally discouraged.</td>
70 </tr><tr> 70 </tr><tr>
71 <td><a href="#continued_indentation">continued_indentation</a></td> 71 <td><a href="#continued_indentation">continued_indentation</a></td>
72 <td></td> 72 <td>Continuation lines should align wrapped elements either vertically using Python's implicit line joining inside parentheses, brackets and braces, or using a hanging indent.</td>
73 </tr><tr> 73 </tr><tr>
74 <td><a href="#expand_indent">expand_indent</a></td> 74 <td><a href="#expand_indent">expand_indent</a></td>
75 <td></td> 75 <td>Return the amount of indentation.</td>
76 </tr><tr> 76 </tr><tr>
77 <td><a href="#explicit_line_join">explicit_line_join</a></td> 77 <td><a href="#explicit_line_join">explicit_line_join</a></td>
78 <td></td> 78 <td>Avoid explicit line join between brackets.</td>
79 </tr><tr> 79 </tr><tr>
80 <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td> 80 <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td>
81 <td>Avoid extraneous whitespace in the following situations:</td> 81 <td>Avoid extraneous whitespace in the following situations:</td>
82 </tr><tr> 82 </tr><tr>
83 <td><a href="#filename_match">filename_match</a></td> 83 <td><a href="#filename_match">filename_match</a></td>
88 </tr><tr> 88 </tr><tr>
89 <td><a href="#get_parser">get_parser</a></td> 89 <td><a href="#get_parser">get_parser</a></td>
90 <td></td> 90 <td></td>
91 </tr><tr> 91 </tr><tr>
92 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td> 92 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td>
93 <td></td> 93 <td>Imports should usually be on separate lines.</td>
94 </tr><tr> 94 </tr><tr>
95 <td><a href="#indentation">indentation</a></td> 95 <td><a href="#indentation">indentation</a></td>
96 <td></td> 96 <td>Use 4 spaces per indentation level.</td>
97 </tr><tr> 97 </tr><tr>
98 <td><a href="#init_checks_registry">init_checks_registry</a></td> 98 <td><a href="#init_checks_registry">init_checks_registry</a></td>
99 <td>Register all globally visible functions where the first argument name is 'physical_line' or 'logical_line'.</td> 99 <td>Register all globally visible functions where the first argument name is 'physical_line' or 'logical_line'.</td>
100 </tr><tr> 100 </tr><tr>
101 <td><a href="#maximum_line_length">maximum_line_length</a></td> 101 <td><a href="#maximum_line_length">maximum_line_length</a></td>
106 </tr><tr> 106 </tr><tr>
107 <td><a href="#missing_whitespace">missing_whitespace</a></td> 107 <td><a href="#missing_whitespace">missing_whitespace</a></td>
108 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td> 108 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td>
109 </tr><tr> 109 </tr><tr>
110 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td> 110 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td>
111 <td></td> 111 <td>- Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).</td>
112 </tr><tr> 112 </tr><tr>
113 <td><a href="#mute_string">mute_string</a></td> 113 <td><a href="#mute_string">mute_string</a></td>
114 <td>Replace contents with 'xxx' to prevent syntax matching.</td> 114 <td>Replace contents with 'xxx' to prevent syntax matching.</td>
115 </tr><tr> 115 </tr><tr>
116 <td><a href="#parse_udiff">parse_udiff</a></td> 116 <td><a href="#parse_udiff">parse_udiff</a></td>
121 </tr><tr> 121 </tr><tr>
122 <td><a href="#python_3000_backticks">python_3000_backticks</a></td> 122 <td><a href="#python_3000_backticks">python_3000_backticks</a></td>
123 <td>Backticks are removed in Python 3.</td> 123 <td>Backticks are removed in Python 3.</td>
124 </tr><tr> 124 </tr><tr>
125 <td><a href="#python_3000_has_key">python_3000_has_key</a></td> 125 <td><a href="#python_3000_has_key">python_3000_has_key</a></td>
126 <td></td> 126 <td>The {}.has_key() method is removed in the Python 3.</td>
127 </tr><tr> 127 </tr><tr>
128 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td> 128 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td>
129 <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td> 129 <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td>
130 </tr><tr> 130 </tr><tr>
131 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td> 131 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td>
145 </tr><tr> 145 </tr><tr>
146 <td><a href="#stdin_get_value">stdin_get_value</a></td> 146 <td><a href="#stdin_get_value">stdin_get_value</a></td>
147 <td></td> 147 <td></td>
148 </tr><tr> 148 </tr><tr>
149 <td><a href="#tabs_obsolete">tabs_obsolete</a></td> 149 <td><a href="#tabs_obsolete">tabs_obsolete</a></td>
150 <td></td> 150 <td>For new projects, spaces-only are strongly recommended over tabs.</td>
151 </tr><tr> 151 </tr><tr>
152 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td> 152 <td><a href="#tabs_or_spaces">tabs_or_spaces</a></td>
153 <td></td> 153 <td>Never mix tabs and spaces.</td>
154 </tr><tr> 154 </tr><tr>
155 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td> 155 <td><a href="#trailing_blank_lines">trailing_blank_lines</a></td>
156 <td></td> 156 <td>JCR: Trailing blank lines are superfluous.</td>
157 </tr><tr> 157 </tr><tr>
158 <td><a href="#trailing_whitespace">trailing_whitespace</a></td> 158 <td><a href="#trailing_whitespace">trailing_whitespace</a></td>
159 <td></td> 159 <td>JCR: Trailing whitespace is superfluous.</td>
160 </tr><tr> 160 </tr><tr>
161 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td> 161 <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td>
162 <td>Avoid extraneous whitespace in the following situations:</td> 162 <td>Avoid extraneous whitespace in the following situations:</td>
163 </tr><tr> 163 </tr><tr>
164 <td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td> 164 <td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td>
165 <td></td> 165 <td>Avoid extraneous whitespace around keywords.</td>
166 </tr><tr> 166 </tr><tr>
167 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td> 167 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td>
168 <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td> 168 <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td>
169 </tr><tr> 169 </tr><tr>
170 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td> 170 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td>
646 <div align="right"><a href="#top">Up</a></div> 646 <div align="right"><a href="#top">Up</a></div>
647 <hr /><hr /> 647 <hr /><hr />
648 <a NAME="blank_lines" ID="blank_lines"></a> 648 <a NAME="blank_lines" ID="blank_lines"></a>
649 <h2>blank_lines</h2> 649 <h2>blank_lines</h2>
650 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level</i>) 650 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level</i>)
651 651 <p>
652 Separate top-level function and class definitions with two blank lines.
653 </p><p>
654 Method definitions inside a class are separated by a single blank line.
655 </p><p>
656 Extra blank lines may be used (sparingly) to separate groups of related
657 functions. Blank lines may be omitted between a bunch of related
658 one-liners (e.g. a set of dummy implementations).
659 </p><p>
660 Use blank lines in functions, sparingly, to indicate logical sections.
661 </p><p>
662 Okay: def a():\n pass\n\n\ndef b():\n pass
663 Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass
664 </p><p>
665 E301: class Foo:\n b = 0\n def bar():\n pass
666 E302: def a():\n pass\n\ndef b(n):\n pass
667 E303: def a():\n pass\n\n\n\ndef b(n):\n pass
668 E303: def a():\n\n\n\n pass
669 E304: @decorator\n\ndef a():\n pass
670 </p>
652 <div align="right"><a href="#top">Up</a></div> 671 <div align="right"><a href="#top">Up</a></div>
653 <hr /><hr /> 672 <hr /><hr />
654 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a> 673 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a>
655 <h2>comparison_to_singleton</h2> 674 <h2>comparison_to_singleton</h2>
656 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>) 675 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>)
689 <div align="right"><a href="#top">Up</a></div> 708 <div align="right"><a href="#top">Up</a></div>
690 <hr /><hr /> 709 <hr /><hr />
691 <a NAME="compound_statements" ID="compound_statements"></a> 710 <a NAME="compound_statements" ID="compound_statements"></a>
692 <h2>compound_statements</h2> 711 <h2>compound_statements</h2>
693 <b>compound_statements</b>(<i>logical_line</i>) 712 <b>compound_statements</b>(<i>logical_line</i>)
694 713 <p>
714 Compound statements (multiple statements on the same line) are
715 generally discouraged.
716 </p><p>
717 While sometimes it's okay to put an if/for/while with a small body
718 on the same line, never do this for multi-clause statements. Also
719 avoid folding such long lines!
720 </p><p>
721 Okay: if foo == 'blah':\n do_blah_thing()
722 Okay: do_one()
723 Okay: do_two()
724 Okay: do_three()
725 </p><p>
726 E701: if foo == 'blah': do_blah_thing()
727 E701: for x in lst: total += x
728 E701: while t < 10: t = delay()
729 E701: if foo == 'blah': do_blah_thing()
730 E701: else: do_non_blah_thing()
731 E701: try: something()
732 E701: finally: cleanup()
733 E701: if foo == 'blah': one(); two(); three()
734 </p><p>
735 E702: do_one(); do_two(); do_three()
736 E703: do_four(); # useless semicolon
737 </p>
695 <div align="right"><a href="#top">Up</a></div> 738 <div align="right"><a href="#top">Up</a></div>
696 <hr /><hr /> 739 <hr /><hr />
697 <a NAME="continued_indentation" ID="continued_indentation"></a> 740 <a NAME="continued_indentation" ID="continued_indentation"></a>
698 <h2>continued_indentation</h2> 741 <h2>continued_indentation</h2>
699 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, noqa, verbose</i>) 742 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, noqa, verbose</i>)
700 743 <p>
744 Continuation lines should align wrapped elements either vertically using
745 Python's implicit line joining inside parentheses, brackets and braces, or
746 using a hanging indent.
747 </p><p>
748 When using a hanging indent the following considerations should be applied:
749 </p><p>
750 - there should be no arguments on the first line, and
751 </p><p>
752 - further indentation should be used to clearly distinguish itself as a
753 continuation line.
754 </p><p>
755 Okay: a = (\n)
756 E123: a = (\n )
757 </p><p>
758 Okay: a = (\n 42)
759 E121: a = (\n 42)
760 E122: a = (\n42)
761 E123: a = (\n 42\n )
762 E124: a = (24,\n 42\n)
763 E125: if (a or\n b):\n pass
764 E126: a = (\n 42)
765 E127: a = (24,\n 42)
766 E128: a = (24,\n 42)
767 </p>
701 <div align="right"><a href="#top">Up</a></div> 768 <div align="right"><a href="#top">Up</a></div>
702 <hr /><hr /> 769 <hr /><hr />
703 <a NAME="expand_indent" ID="expand_indent"></a> 770 <a NAME="expand_indent" ID="expand_indent"></a>
704 <h2>expand_indent</h2> 771 <h2>expand_indent</h2>
705 <b>expand_indent</b>(<i>line</i>) 772 <b>expand_indent</b>(<i>line</i>)
706 773 <p>
774 Return the amount of indentation.
775 Tabs are expanded to the next multiple of 8.
776 </p><p>
777 >>> expand_indent(' ')
778 4
779 >>> expand_indent('\t')
780 8
781 >>> expand_indent(' \t')
782 8
783 >>> expand_indent(' \t')
784 8
785 >>> expand_indent(' \t')
786 16
787 </p>
707 <div align="right"><a href="#top">Up</a></div> 788 <div align="right"><a href="#top">Up</a></div>
708 <hr /><hr /> 789 <hr /><hr />
709 <a NAME="explicit_line_join" ID="explicit_line_join"></a> 790 <a NAME="explicit_line_join" ID="explicit_line_join"></a>
710 <h2>explicit_line_join</h2> 791 <h2>explicit_line_join</h2>
711 <b>explicit_line_join</b>(<i>logical_line, tokens</i>) 792 <b>explicit_line_join</b>(<i>logical_line, tokens</i>)
712 793 <p>
794 Avoid explicit line join between brackets.
795 </p><p>
796 The preferred way of wrapping long lines is by using Python's implied line
797 continuation inside parentheses, brackets and braces. Long lines can be
798 broken over multiple lines by wrapping expressions in parentheses. These
799 should be used in preference to using a backslash for line continuation.
800 </p><p>
801 E502: aaa = [123, \\n 123]
802 E502: aaa = ("bbb " \\n "ccc")
803 </p><p>
804 Okay: aaa = [123,\n 123]
805 Okay: aaa = ("bbb "\n "ccc")
806 Okay: aaa = "bbb " \\n "ccc"
807 </p>
713 <div align="right"><a href="#top">Up</a></div> 808 <div align="right"><a href="#top">Up</a></div>
714 <hr /><hr /> 809 <hr /><hr />
715 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a> 810 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a>
716 <h2>extraneous_whitespace</h2> 811 <h2>extraneous_whitespace</h2>
717 <b>extraneous_whitespace</b>(<i>logical_line</i>) 812 <b>extraneous_whitespace</b>(<i>logical_line</i>)
773 <div align="right"><a href="#top">Up</a></div> 868 <div align="right"><a href="#top">Up</a></div>
774 <hr /><hr /> 869 <hr /><hr />
775 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a> 870 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a>
776 <h2>imports_on_separate_lines</h2> 871 <h2>imports_on_separate_lines</h2>
777 <b>imports_on_separate_lines</b>(<i>logical_line</i>) 872 <b>imports_on_separate_lines</b>(<i>logical_line</i>)
778 873 <p>
874 Imports should usually be on separate lines.
875 </p><p>
876 Okay: import os\nimport sys
877 E401: import sys, os
878 </p><p>
879 Okay: from subprocess import Popen, PIPE
880 Okay: from myclas import MyClass
881 Okay: from foo.bar.yourclass import YourClass
882 Okay: import myclass
883 Okay: import foo.bar.yourclass
884 </p>
779 <div align="right"><a href="#top">Up</a></div> 885 <div align="right"><a href="#top">Up</a></div>
780 <hr /><hr /> 886 <hr /><hr />
781 <a NAME="indentation" ID="indentation"></a> 887 <a NAME="indentation" ID="indentation"></a>
782 <h2>indentation</h2> 888 <h2>indentation</h2>
783 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>) 889 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>)
784 890 <p>
891 Use 4 spaces per indentation level.
892 </p><p>
893 For really old code that you don't want to mess up, you can continue to
894 use 8-space tabs.
895 </p><p>
896 Okay: a = 1
897 Okay: if a == 0:\n a = 1
898 E111: a = 1
899 </p><p>
900 Okay: for item in items:\n pass
901 E112: for item in items:\npass
902 </p><p>
903 Okay: a = 1\nb = 2
904 E113: a = 1\n b = 2
905 </p>
785 <div align="right"><a href="#top">Up</a></div> 906 <div align="right"><a href="#top">Up</a></div>
786 <hr /><hr /> 907 <hr /><hr />
787 <a NAME="init_checks_registry" ID="init_checks_registry"></a> 908 <a NAME="init_checks_registry" ID="init_checks_registry"></a>
788 <h2>init_checks_registry</h2> 909 <h2>init_checks_registry</h2>
789 <b>init_checks_registry</b>(<i></i>) 910 <b>init_checks_registry</b>(<i></i>)
839 <div align="right"><a href="#top">Up</a></div> 960 <div align="right"><a href="#top">Up</a></div>
840 <hr /><hr /> 961 <hr /><hr />
841 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a> 962 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a>
842 <h2>missing_whitespace_around_operator</h2> 963 <h2>missing_whitespace_around_operator</h2>
843 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>) 964 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>)
844 965 <p>
966 - Always surround these binary operators with a single space on
967 either side: assignment (=), augmented assignment (+=, -= etc.),
968 comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
969 Booleans (and, or, not).
970 </p><p>
971 - Use spaces around arithmetic operators.
972 </p><p>
973 Okay: i = i + 1
974 Okay: submitted += 1
975 Okay: x = x * 2 - 1
976 Okay: hypot2 = x * x + y * y
977 Okay: c = (a + b) * (a - b)
978 Okay: foo(bar, key='word', *args, **kwargs)
979 Okay: alpha[:-i]
980 </p><p>
981 E225: i=i+1
982 E225: submitted +=1
983 E225: x = x /2 - 1
984 E225: z = x **y
985 E226: c = (a+b) * (a-b)
986 E226: hypot2 = x*x + y*y
987 E227: c = a|b
988 E228: msg = fmt%(errno, errmsg)
989 </p>
845 <div align="right"><a href="#top">Up</a></div> 990 <div align="right"><a href="#top">Up</a></div>
846 <hr /><hr /> 991 <hr /><hr />
847 <a NAME="mute_string" ID="mute_string"></a> 992 <a NAME="mute_string" ID="mute_string"></a>
848 <h2>mute_string</h2> 993 <h2>mute_string</h2>
849 <b>mute_string</b>(<i>text</i>) 994 <b>mute_string</b>(<i>text</i>)
888 <div align="right"><a href="#top">Up</a></div> 1033 <div align="right"><a href="#top">Up</a></div>
889 <hr /><hr /> 1034 <hr /><hr />
890 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a> 1035 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a>
891 <h2>python_3000_has_key</h2> 1036 <h2>python_3000_has_key</h2>
892 <b>python_3000_has_key</b>(<i>logical_line</i>) 1037 <b>python_3000_has_key</b>(<i>logical_line</i>)
893 1038 <p>
1039 The {}.has_key() method is removed in the Python 3.
1040 Use the 'in' operation instead.
1041 </p><p>
1042 Okay: if "alph" in d:\n print d["alph"]
1043 W601: assert d.has_key('alph')
1044 </p>
894 <div align="right"><a href="#top">Up</a></div> 1045 <div align="right"><a href="#top">Up</a></div>
895 <hr /><hr /> 1046 <hr /><hr />
896 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a> 1047 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a>
897 <h2>python_3000_not_equal</h2> 1048 <h2>python_3000_not_equal</h2>
898 <b>python_3000_not_equal</b>(<i>logical_line</i>) 1049 <b>python_3000_not_equal</b>(<i>logical_line</i>)
958 <div align="right"><a href="#top">Up</a></div> 1109 <div align="right"><a href="#top">Up</a></div>
959 <hr /><hr /> 1110 <hr /><hr />
960 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a> 1111 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a>
961 <h2>tabs_obsolete</h2> 1112 <h2>tabs_obsolete</h2>
962 <b>tabs_obsolete</b>(<i>physical_line</i>) 1113 <b>tabs_obsolete</b>(<i>physical_line</i>)
963 1114 <p>
1115 For new projects, spaces-only are strongly recommended over tabs. Most
1116 editors have features that make this easy to do.
1117 </p><p>
1118 Okay: if True:\n return
1119 W191: if True:\n\treturn
1120 </p>
964 <div align="right"><a href="#top">Up</a></div> 1121 <div align="right"><a href="#top">Up</a></div>
965 <hr /><hr /> 1122 <hr /><hr />
966 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a> 1123 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a>
967 <h2>tabs_or_spaces</h2> 1124 <h2>tabs_or_spaces</h2>
968 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>) 1125 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>)
969 1126 <p>
1127 Never mix tabs and spaces.
1128 </p><p>
1129 The most popular way of indenting Python is with spaces only. The
1130 second-most popular way is with tabs only. Code indented with a mixture
1131 of tabs and spaces should be converted to using spaces exclusively. When
1132 invoking the Python command line interpreter with the -t option, it issues
1133 warnings about code that illegally mixes tabs and spaces. When using -tt
1134 these warnings become errors. These options are highly recommended!
1135 </p><p>
1136 Okay: if a == 0:\n a = 1\n b = 1
1137 E101: if a == 0:\n a = 1\n\tb = 1
1138 </p>
970 <div align="right"><a href="#top">Up</a></div> 1139 <div align="right"><a href="#top">Up</a></div>
971 <hr /><hr /> 1140 <hr /><hr />
972 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a> 1141 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a>
973 <h2>trailing_blank_lines</h2> 1142 <h2>trailing_blank_lines</h2>
974 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>) 1143 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>)
975 1144 <p>
1145 JCR: Trailing blank lines are superfluous.
1146 </p><p>
1147 Okay: spam(1)
1148 W391: spam(1)\n
1149 </p>
976 <div align="right"><a href="#top">Up</a></div> 1150 <div align="right"><a href="#top">Up</a></div>
977 <hr /><hr /> 1151 <hr /><hr />
978 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a> 1152 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a>
979 <h2>trailing_whitespace</h2> 1153 <h2>trailing_whitespace</h2>
980 <b>trailing_whitespace</b>(<i>physical_line</i>) 1154 <b>trailing_whitespace</b>(<i>physical_line</i>)
981 1155 <p>
1156 JCR: Trailing whitespace is superfluous.
1157 FBM: Except when it occurs as part of a blank line (i.e. the line is
1158 nothing but whitespace). According to Python docs[1] a line with only
1159 whitespace is considered a blank line, and is to be ignored. However,
1160 matching a blank line to its indentation level avoids mistakenly
1161 terminating a multi-line statement (e.g. class declaration) when
1162 pasting code into the standard Python interpreter.
1163 </p><p>
1164 [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines
1165 </p><p>
1166 The warning returned varies on whether the line itself is blank, for easier
1167 filtering for those who want to indent their blank lines.
1168 </p><p>
1169 Okay: spam(1)\n#
1170 W291: spam(1) \n#
1171 W293: class Foo(object):\n \n bang = 12
1172 </p>
982 <div align="right"><a href="#top">Up</a></div> 1173 <div align="right"><a href="#top">Up</a></div>
983 <hr /><hr /> 1174 <hr /><hr />
984 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a> 1175 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a>
985 <h2>whitespace_around_comma</h2> 1176 <h2>whitespace_around_comma</h2>
986 <b>whitespace_around_comma</b>(<i>logical_line</i>) 1177 <b>whitespace_around_comma</b>(<i>logical_line</i>)
1000 <div align="right"><a href="#top">Up</a></div> 1191 <div align="right"><a href="#top">Up</a></div>
1001 <hr /><hr /> 1192 <hr /><hr />
1002 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a> 1193 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a>
1003 <h2>whitespace_around_keywords</h2> 1194 <h2>whitespace_around_keywords</h2>
1004 <b>whitespace_around_keywords</b>(<i>logical_line</i>) 1195 <b>whitespace_around_keywords</b>(<i>logical_line</i>)
1005 1196 <p>
1197 Avoid extraneous whitespace around keywords.
1198 </p><p>
1199 Okay: True and False
1200 E271: True and False
1201 E272: True and False
1202 E273: True and\tFalse
1203 E274: True\tand False
1204 </p>
1006 <div align="right"><a href="#top">Up</a></div> 1205 <div align="right"><a href="#top">Up</a></div>
1007 <hr /><hr /> 1206 <hr /><hr />
1008 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a> 1207 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a>
1009 <h2>whitespace_around_named_parameter_equals</h2> 1208 <h2>whitespace_around_named_parameter_equals</h2>
1010 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>) 1209 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>)

eric ide

mercurial