Documentation/Source/eric5.UtilitiesPython2.pep8.html

changeset 2923
01ac1f364b38
parent 2867
eb325d7f7335
child 3217
87b8a0745edd
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>
85 </tr><tr> 85 </tr><tr>
86 <td><a href="#get_parser">get_parser</a></td> 86 <td><a href="#get_parser">get_parser</a></td>
87 <td></td> 87 <td></td>
88 </tr><tr> 88 </tr><tr>
89 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td> 89 <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td>
90 <td></td> 90 <td>Imports should usually be on separate lines.</td>
91 </tr><tr> 91 </tr><tr>
92 <td><a href="#indentation">indentation</a></td> 92 <td><a href="#indentation">indentation</a></td>
93 <td></td> 93 <td>Use 4 spaces per indentation level.</td>
94 </tr><tr> 94 </tr><tr>
95 <td><a href="#init_checks_registry">init_checks_registry</a></td> 95 <td><a href="#init_checks_registry">init_checks_registry</a></td>
96 <td>Register all globally visible functions where the first argument name is 'physical_line' or 'logical_line'.</td> 96 <td>Register all globally visible functions where the first argument name is 'physical_line' or 'logical_line'.</td>
97 </tr><tr> 97 </tr><tr>
98 <td><a href="#maximum_line_length">maximum_line_length</a></td> 98 <td><a href="#maximum_line_length">maximum_line_length</a></td>
103 </tr><tr> 103 </tr><tr>
104 <td><a href="#missing_whitespace">missing_whitespace</a></td> 104 <td><a href="#missing_whitespace">missing_whitespace</a></td>
105 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td> 105 <td>JCR: Each comma, semicolon or colon should be followed by whitespace.</td>
106 </tr><tr> 106 </tr><tr>
107 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td> 107 <td><a href="#missing_whitespace_around_operator">missing_whitespace_around_operator</a></td>
108 <td></td> 108 <td>- Always surround these binary operators with a single space on either side: assignment (=), augmented assignment (+=, -= etc.), comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not), Booleans (and, or, not).</td>
109 </tr><tr> 109 </tr><tr>
110 <td><a href="#mute_string">mute_string</a></td> 110 <td><a href="#mute_string">mute_string</a></td>
111 <td>Replace contents with 'xxx' to prevent syntax matching.</td> 111 <td>Replace contents with 'xxx' to prevent syntax matching.</td>
112 </tr><tr> 112 </tr><tr>
113 <td><a href="#parse_udiff">parse_udiff</a></td> 113 <td><a href="#parse_udiff">parse_udiff</a></td>
118 </tr><tr> 118 </tr><tr>
119 <td><a href="#python_3000_backticks">python_3000_backticks</a></td> 119 <td><a href="#python_3000_backticks">python_3000_backticks</a></td>
120 <td>Backticks are removed in Python 3.</td> 120 <td>Backticks are removed in Python 3.</td>
121 </tr><tr> 121 </tr><tr>
122 <td><a href="#python_3000_has_key">python_3000_has_key</a></td> 122 <td><a href="#python_3000_has_key">python_3000_has_key</a></td>
123 <td></td> 123 <td>The {}.has_key() method is removed in the Python 3.</td>
124 </tr><tr> 124 </tr><tr>
125 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td> 125 <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td>
126 <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td> 126 <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td>
127 </tr><tr> 127 </tr><tr>
128 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td> 128 <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td>
142 </tr><tr> 142 </tr><tr>
143 <td><a href="#stdin_get_value">stdin_get_value</a></td> 143 <td><a href="#stdin_get_value">stdin_get_value</a></td>
144 <td></td> 144 <td></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_keywords">whitespace_around_keywords</a></td> 161 <td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td>
162 <td></td> 162 <td>Avoid extraneous whitespace around keywords.</td>
163 </tr><tr> 163 </tr><tr>
164 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td> 164 <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td>
165 <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td> 165 <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td>
166 </tr><tr> 166 </tr><tr>
167 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td> 167 <td><a href="#whitespace_around_operator">whitespace_around_operator</a></td>
643 <div align="right"><a href="#top">Up</a></div> 643 <div align="right"><a href="#top">Up</a></div>
644 <hr /><hr /> 644 <hr /><hr />
645 <a NAME="blank_lines" ID="blank_lines"></a> 645 <a NAME="blank_lines" ID="blank_lines"></a>
646 <h2>blank_lines</h2> 646 <h2>blank_lines</h2>
647 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level</i>) 647 <b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level</i>)
648 648 <p>
649 Separate top-level function and class definitions with two blank lines.
650 </p><p>
651 Method definitions inside a class are separated by a single blank line.
652 </p><p>
653 Extra blank lines may be used (sparingly) to separate groups of related
654 functions. Blank lines may be omitted between a bunch of related
655 one-liners (e.g. a set of dummy implementations).
656 </p><p>
657 Use blank lines in functions, sparingly, to indicate logical sections.
658 </p><p>
659 Okay: def a():\n pass\n\n\ndef b():\n pass
660 Okay: def a():\n pass\n\n\n# Foo\n# Bar\n\ndef b():\n pass
661 </p><p>
662 E301: class Foo:\n b = 0\n def bar():\n pass
663 E302: def a():\n pass\n\ndef b(n):\n pass
664 E303: def a():\n pass\n\n\n\ndef b(n):\n pass
665 E303: def a():\n\n\n\n pass
666 E304: @decorator\n\ndef a():\n pass
667 </p>
649 <div align="right"><a href="#top">Up</a></div> 668 <div align="right"><a href="#top">Up</a></div>
650 <hr /><hr /> 669 <hr /><hr />
651 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a> 670 <a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a>
652 <h2>comparison_to_singleton</h2> 671 <h2>comparison_to_singleton</h2>
653 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>) 672 <b>comparison_to_singleton</b>(<i>logical_line, noqa</i>)
686 <div align="right"><a href="#top">Up</a></div> 705 <div align="right"><a href="#top">Up</a></div>
687 <hr /><hr /> 706 <hr /><hr />
688 <a NAME="compound_statements" ID="compound_statements"></a> 707 <a NAME="compound_statements" ID="compound_statements"></a>
689 <h2>compound_statements</h2> 708 <h2>compound_statements</h2>
690 <b>compound_statements</b>(<i>logical_line</i>) 709 <b>compound_statements</b>(<i>logical_line</i>)
691 710 <p>
711 Compound statements (multiple statements on the same line) are
712 generally discouraged.
713 </p><p>
714 While sometimes it's okay to put an if/for/while with a small body
715 on the same line, never do this for multi-clause statements. Also
716 avoid folding such long lines!
717 </p><p>
718 Okay: if foo == 'blah':\n do_blah_thing()
719 Okay: do_one()
720 Okay: do_two()
721 Okay: do_three()
722 </p><p>
723 E701: if foo == 'blah': do_blah_thing()
724 E701: for x in lst: total += x
725 E701: while t < 10: t = delay()
726 E701: if foo == 'blah': do_blah_thing()
727 E701: else: do_non_blah_thing()
728 E701: try: something()
729 E701: finally: cleanup()
730 E701: if foo == 'blah': one(); two(); three()
731 </p><p>
732 E702: do_one(); do_two(); do_three()
733 E703: do_four(); # useless semicolon
734 </p>
692 <div align="right"><a href="#top">Up</a></div> 735 <div align="right"><a href="#top">Up</a></div>
693 <hr /><hr /> 736 <hr /><hr />
694 <a NAME="continued_indentation" ID="continued_indentation"></a> 737 <a NAME="continued_indentation" ID="continued_indentation"></a>
695 <h2>continued_indentation</h2> 738 <h2>continued_indentation</h2>
696 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, noqa, verbose</i>) 739 <b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, noqa, verbose</i>)
697 740 <p>
741 Continuation lines should align wrapped elements either vertically using
742 Python's implicit line joining inside parentheses, brackets and braces, or
743 using a hanging indent.
744 </p><p>
745 When using a hanging indent the following considerations should be applied:
746 </p><p>
747 - there should be no arguments on the first line, and
748 </p><p>
749 - further indentation should be used to clearly distinguish itself as a
750 continuation line.
751 </p><p>
752 Okay: a = (\n)
753 E123: a = (\n )
754 </p><p>
755 Okay: a = (\n 42)
756 E121: a = (\n 42)
757 E122: a = (\n42)
758 E123: a = (\n 42\n )
759 E124: a = (24,\n 42\n)
760 E125: if (a or\n b):\n pass
761 E126: a = (\n 42)
762 E127: a = (24,\n 42)
763 E128: a = (24,\n 42)
764 </p>
698 <div align="right"><a href="#top">Up</a></div> 765 <div align="right"><a href="#top">Up</a></div>
699 <hr /><hr /> 766 <hr /><hr />
700 <a NAME="expand_indent" ID="expand_indent"></a> 767 <a NAME="expand_indent" ID="expand_indent"></a>
701 <h2>expand_indent</h2> 768 <h2>expand_indent</h2>
702 <b>expand_indent</b>(<i>line</i>) 769 <b>expand_indent</b>(<i>line</i>)
703 770 <p>
771 Return the amount of indentation.
772 Tabs are expanded to the next multiple of 8.
773 </p><p>
774 >>> expand_indent(' ')
775 4
776 >>> expand_indent('\t')
777 8
778 >>> expand_indent(' \t')
779 8
780 >>> expand_indent(' \t')
781 8
782 >>> expand_indent(' \t')
783 16
784 </p>
704 <div align="right"><a href="#top">Up</a></div> 785 <div align="right"><a href="#top">Up</a></div>
705 <hr /><hr /> 786 <hr /><hr />
706 <a NAME="explicit_line_join" ID="explicit_line_join"></a> 787 <a NAME="explicit_line_join" ID="explicit_line_join"></a>
707 <h2>explicit_line_join</h2> 788 <h2>explicit_line_join</h2>
708 <b>explicit_line_join</b>(<i>logical_line, tokens</i>) 789 <b>explicit_line_join</b>(<i>logical_line, tokens</i>)
709 790 <p>
791 Avoid explicit line join between brackets.
792 </p><p>
793 The preferred way of wrapping long lines is by using Python's implied line
794 continuation inside parentheses, brackets and braces. Long lines can be
795 broken over multiple lines by wrapping expressions in parentheses. These
796 should be used in preference to using a backslash for line continuation.
797 </p><p>
798 E502: aaa = [123, \\n 123]
799 E502: aaa = ("bbb " \\n "ccc")
800 </p><p>
801 Okay: aaa = [123,\n 123]
802 Okay: aaa = ("bbb "\n "ccc")
803 Okay: aaa = "bbb " \\n "ccc"
804 </p>
710 <div align="right"><a href="#top">Up</a></div> 805 <div align="right"><a href="#top">Up</a></div>
711 <hr /><hr /> 806 <hr /><hr />
712 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a> 807 <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a>
713 <h2>extraneous_whitespace</h2> 808 <h2>extraneous_whitespace</h2>
714 <b>extraneous_whitespace</b>(<i>logical_line</i>) 809 <b>extraneous_whitespace</b>(<i>logical_line</i>)
749 <div align="right"><a href="#top">Up</a></div> 844 <div align="right"><a href="#top">Up</a></div>
750 <hr /><hr /> 845 <hr /><hr />
751 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a> 846 <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a>
752 <h2>imports_on_separate_lines</h2> 847 <h2>imports_on_separate_lines</h2>
753 <b>imports_on_separate_lines</b>(<i>logical_line</i>) 848 <b>imports_on_separate_lines</b>(<i>logical_line</i>)
754 849 <p>
850 Imports should usually be on separate lines.
851 </p><p>
852 Okay: import os\nimport sys
853 E401: import sys, os
854 </p><p>
855 Okay: from subprocess import Popen, PIPE
856 Okay: from myclas import MyClass
857 Okay: from foo.bar.yourclass import YourClass
858 Okay: import myclass
859 Okay: import foo.bar.yourclass
860 </p>
755 <div align="right"><a href="#top">Up</a></div> 861 <div align="right"><a href="#top">Up</a></div>
756 <hr /><hr /> 862 <hr /><hr />
757 <a NAME="indentation" ID="indentation"></a> 863 <a NAME="indentation" ID="indentation"></a>
758 <h2>indentation</h2> 864 <h2>indentation</h2>
759 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>) 865 <b>indentation</b>(<i>logical_line, previous_logical, indent_char, indent_level, previous_indent_level</i>)
760 866 <p>
867 Use 4 spaces per indentation level.
868 </p><p>
869 For really old code that you don't want to mess up, you can continue to
870 use 8-space tabs.
871 </p><p>
872 Okay: a = 1
873 Okay: if a == 0:\n a = 1
874 E111: a = 1
875 </p><p>
876 Okay: for item in items:\n pass
877 E112: for item in items:\npass
878 </p><p>
879 Okay: a = 1\nb = 2
880 E113: a = 1\n b = 2
881 </p>
761 <div align="right"><a href="#top">Up</a></div> 882 <div align="right"><a href="#top">Up</a></div>
762 <hr /><hr /> 883 <hr /><hr />
763 <a NAME="init_checks_registry" ID="init_checks_registry"></a> 884 <a NAME="init_checks_registry" ID="init_checks_registry"></a>
764 <h2>init_checks_registry</h2> 885 <h2>init_checks_registry</h2>
765 <b>init_checks_registry</b>(<i></i>) 886 <b>init_checks_registry</b>(<i></i>)
815 <div align="right"><a href="#top">Up</a></div> 936 <div align="right"><a href="#top">Up</a></div>
816 <hr /><hr /> 937 <hr /><hr />
817 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a> 938 <a NAME="missing_whitespace_around_operator" ID="missing_whitespace_around_operator"></a>
818 <h2>missing_whitespace_around_operator</h2> 939 <h2>missing_whitespace_around_operator</h2>
819 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>) 940 <b>missing_whitespace_around_operator</b>(<i>logical_line, tokens</i>)
820 941 <p>
942 - Always surround these binary operators with a single space on
943 either side: assignment (=), augmented assignment (+=, -= etc.),
944 comparisons (==, <, >, !=, <>, <=, >=, in, not in, is, is not),
945 Booleans (and, or, not).
946 </p><p>
947 - Use spaces around arithmetic operators.
948 </p><p>
949 Okay: i = i + 1
950 Okay: submitted += 1
951 Okay: x = x * 2 - 1
952 Okay: hypot2 = x * x + y * y
953 Okay: c = (a + b) * (a - b)
954 Okay: foo(bar, key='word', *args, **kwargs)
955 Okay: alpha[:-i]
956 </p><p>
957 E225: i=i+1
958 E225: submitted +=1
959 E225: x = x /2 - 1
960 E225: z = x **y
961 E226: c = (a+b) * (a-b)
962 E226: hypot2 = x*x + y*y
963 E227: c = a|b
964 E228: msg = fmt%(errno, errmsg)
965 </p>
821 <div align="right"><a href="#top">Up</a></div> 966 <div align="right"><a href="#top">Up</a></div>
822 <hr /><hr /> 967 <hr /><hr />
823 <a NAME="mute_string" ID="mute_string"></a> 968 <a NAME="mute_string" ID="mute_string"></a>
824 <h2>mute_string</h2> 969 <h2>mute_string</h2>
825 <b>mute_string</b>(<i>text</i>) 970 <b>mute_string</b>(<i>text</i>)
864 <div align="right"><a href="#top">Up</a></div> 1009 <div align="right"><a href="#top">Up</a></div>
865 <hr /><hr /> 1010 <hr /><hr />
866 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a> 1011 <a NAME="python_3000_has_key" ID="python_3000_has_key"></a>
867 <h2>python_3000_has_key</h2> 1012 <h2>python_3000_has_key</h2>
868 <b>python_3000_has_key</b>(<i>logical_line</i>) 1013 <b>python_3000_has_key</b>(<i>logical_line</i>)
869 1014 <p>
1015 The {}.has_key() method is removed in the Python 3.
1016 Use the 'in' operation instead.
1017 </p><p>
1018 Okay: if "alph" in d:\n print d["alph"]
1019 W601: assert d.has_key('alph')
1020 </p>
870 <div align="right"><a href="#top">Up</a></div> 1021 <div align="right"><a href="#top">Up</a></div>
871 <hr /><hr /> 1022 <hr /><hr />
872 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a> 1023 <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a>
873 <h2>python_3000_not_equal</h2> 1024 <h2>python_3000_not_equal</h2>
874 <b>python_3000_not_equal</b>(<i>logical_line</i>) 1025 <b>python_3000_not_equal</b>(<i>logical_line</i>)
934 <div align="right"><a href="#top">Up</a></div> 1085 <div align="right"><a href="#top">Up</a></div>
935 <hr /><hr /> 1086 <hr /><hr />
936 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a> 1087 <a NAME="tabs_obsolete" ID="tabs_obsolete"></a>
937 <h2>tabs_obsolete</h2> 1088 <h2>tabs_obsolete</h2>
938 <b>tabs_obsolete</b>(<i>physical_line</i>) 1089 <b>tabs_obsolete</b>(<i>physical_line</i>)
939 1090 <p>
1091 For new projects, spaces-only are strongly recommended over tabs. Most
1092 editors have features that make this easy to do.
1093 </p><p>
1094 Okay: if True:\n return
1095 W191: if True:\n\treturn
1096 </p>
940 <div align="right"><a href="#top">Up</a></div> 1097 <div align="right"><a href="#top">Up</a></div>
941 <hr /><hr /> 1098 <hr /><hr />
942 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a> 1099 <a NAME="tabs_or_spaces" ID="tabs_or_spaces"></a>
943 <h2>tabs_or_spaces</h2> 1100 <h2>tabs_or_spaces</h2>
944 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>) 1101 <b>tabs_or_spaces</b>(<i>physical_line, indent_char</i>)
945 1102 <p>
1103 Never mix tabs and spaces.
1104 </p><p>
1105 The most popular way of indenting Python is with spaces only. The
1106 second-most popular way is with tabs only. Code indented with a mixture
1107 of tabs and spaces should be converted to using spaces exclusively. When
1108 invoking the Python command line interpreter with the -t option, it issues
1109 warnings about code that illegally mixes tabs and spaces. When using -tt
1110 these warnings become errors. These options are highly recommended!
1111 </p><p>
1112 Okay: if a == 0:\n a = 1\n b = 1
1113 E101: if a == 0:\n a = 1\n\tb = 1
1114 </p>
946 <div align="right"><a href="#top">Up</a></div> 1115 <div align="right"><a href="#top">Up</a></div>
947 <hr /><hr /> 1116 <hr /><hr />
948 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a> 1117 <a NAME="trailing_blank_lines" ID="trailing_blank_lines"></a>
949 <h2>trailing_blank_lines</h2> 1118 <h2>trailing_blank_lines</h2>
950 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>) 1119 <b>trailing_blank_lines</b>(<i>physical_line, lines, line_number</i>)
951 1120 <p>
1121 JCR: Trailing blank lines are superfluous.
1122 </p><p>
1123 Okay: spam(1)
1124 W391: spam(1)\n
1125 </p>
952 <div align="right"><a href="#top">Up</a></div> 1126 <div align="right"><a href="#top">Up</a></div>
953 <hr /><hr /> 1127 <hr /><hr />
954 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a> 1128 <a NAME="trailing_whitespace" ID="trailing_whitespace"></a>
955 <h2>trailing_whitespace</h2> 1129 <h2>trailing_whitespace</h2>
956 <b>trailing_whitespace</b>(<i>physical_line</i>) 1130 <b>trailing_whitespace</b>(<i>physical_line</i>)
957 1131 <p>
1132 JCR: Trailing whitespace is superfluous.
1133 FBM: Except when it occurs as part of a blank line (i.e. the line is
1134 nothing but whitespace). According to Python docs[1] a line with only
1135 whitespace is considered a blank line, and is to be ignored. However,
1136 matching a blank line to its indentation level avoids mistakenly
1137 terminating a multi-line statement (e.g. class declaration) when
1138 pasting code into the standard Python interpreter.
1139 </p><p>
1140 [1] http://docs.python.org/reference/lexical_analysis.html#blank-lines
1141 </p><p>
1142 The warning returned varies on whether the line itself is blank, for easier
1143 filtering for those who want to indent their blank lines.
1144 </p><p>
1145 Okay: spam(1)\n#
1146 W291: spam(1) \n#
1147 W293: class Foo(object):\n \n bang = 12
1148 </p>
958 <div align="right"><a href="#top">Up</a></div> 1149 <div align="right"><a href="#top">Up</a></div>
959 <hr /><hr /> 1150 <hr /><hr />
960 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a> 1151 <a NAME="whitespace_around_comma" ID="whitespace_around_comma"></a>
961 <h2>whitespace_around_comma</h2> 1152 <h2>whitespace_around_comma</h2>
962 <b>whitespace_around_comma</b>(<i>logical_line</i>) 1153 <b>whitespace_around_comma</b>(<i>logical_line</i>)
976 <div align="right"><a href="#top">Up</a></div> 1167 <div align="right"><a href="#top">Up</a></div>
977 <hr /><hr /> 1168 <hr /><hr />
978 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a> 1169 <a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a>
979 <h2>whitespace_around_keywords</h2> 1170 <h2>whitespace_around_keywords</h2>
980 <b>whitespace_around_keywords</b>(<i>logical_line</i>) 1171 <b>whitespace_around_keywords</b>(<i>logical_line</i>)
981 1172 <p>
1173 Avoid extraneous whitespace around keywords.
1174 </p><p>
1175 Okay: True and False
1176 E271: True and False
1177 E272: True and False
1178 E273: True and\tFalse
1179 E274: True\tand False
1180 </p>
982 <div align="right"><a href="#top">Up</a></div> 1181 <div align="right"><a href="#top">Up</a></div>
983 <hr /><hr /> 1182 <hr /><hr />
984 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a> 1183 <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a>
985 <h2>whitespace_around_named_parameter_equals</h2> 1184 <h2>whitespace_around_named_parameter_equals</h2>
986 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>) 1185 <b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>)

eric ide

mercurial