--- a/Documentation/Source/eric5.Plugins.CheckerPlugins.Pep8.pep8.html Sat Aug 24 14:44:55 2013 +0200 +++ b/Documentation/Source/eric5.Plugins.CheckerPlugins.Pep8.pep8.html Sat Aug 24 15:05:05 2013 +0200 @@ -23,59 +23,71 @@ <h3>Global Attributes</h3> <table> -<tr><td>BENCHMARK_KEYS</td></tr><tr><td>BINARY_OPERATORS</td></tr><tr><td>DEFAULT_EXCLUDE</td></tr><tr><td>DEFAULT_IGNORE</td></tr><tr><td>DOCSTRING_REGEX</td></tr><tr><td>E225NOT_KEYWORDS</td></tr><tr><td>ERRORCODE_REGEX</td></tr><tr><td>EXTRANEOUS_WHITESPACE_REGEX</td></tr><tr><td>INDENT_REGEX</td></tr><tr><td>MAX_LINE_LENGTH</td></tr><tr><td>OPERATORS</td></tr><tr><td>RAISE_COMMA_REGEX</td></tr><tr><td>SELFTEST_REGEX</td></tr><tr><td>SKIP_TOKENS</td></tr><tr><td>UNARY_OPERATORS</td></tr><tr><td>WHITESPACE</td></tr><tr><td>WHITESPACE_AROUND_NAMED_PARAMETER_REGEX</td></tr><tr><td>WHITESPACE_AROUND_OPERATOR_REGEX</td></tr><tr><td>__version__</td></tr><tr><td>args</td></tr><tr><td>options</td></tr><tr><td>pep8_messages</td></tr><tr><td>pep8_messages_sample_args</td></tr> +<tr><td>ARITHMETIC_OP</td></tr><tr><td>BENCHMARK_KEYS</td></tr><tr><td>COMMENT_WITH_NL</td></tr><tr><td>COMPARE_SINGLETON_REGEX</td></tr><tr><td>COMPARE_TYPE_REGEX</td></tr><tr><td>DEFAULT_EXCLUDE</td></tr><tr><td>DEFAULT_IGNORE</td></tr><tr><td>DOCSTRING_REGEX</td></tr><tr><td>ERRORCODE_REGEX</td></tr><tr><td>EXTRANEOUS_WHITESPACE_REGEX</td></tr><tr><td>HUNK_REGEX</td></tr><tr><td>INDENT_REGEX</td></tr><tr><td>KEYWORDS</td></tr><tr><td>KEYWORD_REGEX</td></tr><tr><td>LAMBDA_REGEX</td></tr><tr><td>MAX_LINE_LENGTH</td></tr><tr><td>OPERATOR_REGEX</td></tr><tr><td>PROJECT_CONFIG</td></tr><tr><td>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_TOKENS</td></tr><tr><td>TESTSUITE_PATH</td></tr><tr><td>UNARY_OPERATORS</td></tr><tr><td>WHITESPACE</td></tr><tr><td>WHITESPACE_AFTER_COMMA_REGEX</td></tr><tr><td>WS_NEEDED_OPERATORS</td></tr><tr><td>WS_OPTIONAL_OPERATORS</td></tr><tr><td>__version__</td></tr><tr><td>_checks</td></tr><tr><td>noqa</td></tr><tr><td>pep8_messages</td></tr><tr><td>pep8_messages_sample_args</td></tr> </table> <h3>Classes</h3> <table> <tr> +<td><a href="#BaseReport">BaseReport</a></td> +<td>Collect the results of the checks.</td> +</tr><tr> <td><a href="#Checker">Checker</a></td> <td>Load a Python source file, tokenize it, check coding style.</td> +</tr><tr> +<td><a href="#DiffReport">DiffReport</a></td> +<td>Collect and print the results for the changed lines only.</td> +</tr><tr> +<td><a href="#FileReport">FileReport</a></td> +<td>Collect the results of the checks and print only the filenames.</td> +</tr><tr> +<td><a href="#StandardReport">StandardReport</a></td> +<td>Collect and print the results of the checks.</td> +</tr><tr> +<td><a href="#StyleGuide">StyleGuide</a></td> +<td>Initialize a PEP-8 instance with few options.</td> </tr> </table> <h3>Functions</h3> <table> <tr> +<td><a href="#_add_check">_add_check</a></td> +<td></td> +</tr><tr> <td><a href="#_main">_main</a></td> <td>Parse options and run checks on Python source.</td> </tr><tr> <td><a href="#blank_lines">blank_lines</a></td> <td></td> </tr><tr> +<td><a href="#comparison_to_singleton">comparison_to_singleton</a></td> +<td>Comparisons to singletons like None should always be done with "is" or "is not", never the equality operators.</td> +</tr><tr> +<td><a href="#comparison_type">comparison_type</a></td> +<td>Object type comparisons should always use isinstance() instead of comparing types directly.</td> +</tr><tr> <td><a href="#compound_statements">compound_statements</a></td> <td></td> </tr><tr> -<td><a href="#excluded">excluded</a></td> -<td>Check if options.exclude contains a pattern that matches filename.</td> +<td><a href="#continued_indentation">continued_indentation</a></td> +<td></td> </tr><tr> <td><a href="#expand_indent">expand_indent</a></td> -<td>Return the amount of indentation.</td> +<td></td> +</tr><tr> +<td><a href="#explicit_line_join">explicit_line_join</a></td> +<td></td> </tr><tr> <td><a href="#extraneous_whitespace">extraneous_whitespace</a></td> <td>Avoid extraneous whitespace in the following situations:</td> </tr><tr> <td><a href="#filename_match">filename_match</a></td> -<td>Check if options.filename contains a pattern that matches filename.</td> -</tr><tr> -<td><a href="#find_checks">find_checks</a></td> -<td>Find all globally visible functions where the first argument name starts with argument_name.</td> +<td>Check if patterns contains a pattern that matches filename.</td> </tr><tr> <td><a href="#getMessage">getMessage</a></td> <td>Function to get a translated and formatted message for a given code.</td> </tr><tr> -<td><a href="#get_count">get_count</a></td> -<td>Return the total count of errors and warnings.</td> -</tr><tr> -<td><a href="#get_error_statistics">get_error_statistics</a></td> -<td>Get error statistics.</td> -</tr><tr> -<td><a href="#get_statistics">get_statistics</a></td> -<td>Get statistics for message codes that start with the prefix.</td> -</tr><tr> -<td><a href="#get_warning_statistics">get_warning_statistics</a></td> -<td>Get warning statistics.</td> -</tr><tr> -<td><a href="#ignore_code">ignore_code</a></td> -<td>Check if options.ignore contains a prefix of the error code.</td> +<td><a href="#get_parser">get_parser</a></td> +<td></td> </tr><tr> <td><a href="#imports_on_separate_lines">imports_on_separate_lines</a></td> <td></td> @@ -83,18 +95,12 @@ <td><a href="#indentation">indentation</a></td> <td></td> </tr><tr> -<td><a href="#input_dir">input_dir</a></td> -<td>Check all Python source files in this directory and all subdirectories.</td> -</tr><tr> -<td><a href="#input_file">input_file</a></td> -<td>Run all checks on a Python source file.</td> +<td><a href="#init_checks_registry">init_checks_registry</a></td> +<td>Register all globally visible functions where the first argument name is 'physical_line' or 'logical_line'.</td> </tr><tr> <td><a href="#maximum_line_length">maximum_line_length</a></td> <td>Limit all lines to a maximum of 79 characters.</td> </tr><tr> -<td><a href="#message">message</a></td> -<td>Print a message.</td> -</tr><tr> <td><a href="#missing_newline">missing_newline</a></td> <td>JCR: The last line should have a newline.</td> </tr><tr> @@ -107,20 +113,17 @@ <td><a href="#mute_string">mute_string</a></td> <td>Replace contents with 'xxx' to prevent syntax matching.</td> </tr><tr> -<td><a href="#print_benchmark">print_benchmark</a></td> -<td>Print benchmark numbers.</td> -</tr><tr> -<td><a href="#print_statistics">print_statistics</a></td> -<td>Print overall statistics (number of errors and warnings).</td> +<td><a href="#parse_udiff">parse_udiff</a></td> +<td>Return a dictionary of matching lines.</td> </tr><tr> <td><a href="#process_options">process_options</a></td> <td>Process options passed either via arglist or via command line args.</td> </tr><tr> <td><a href="#python_3000_backticks">python_3000_backticks</a></td> -<td>Backticks are removed in Python 3000.</td> +<td>Backticks are removed in Python 3.</td> </tr><tr> <td><a href="#python_3000_has_key">python_3000_has_key</a></td> -<td>The {}.has_key() method will be removed in the future version of Python.</td> +<td></td> </tr><tr> <td><a href="#python_3000_not_equal">python_3000_not_equal</a></td> <td>!= can also be written <>, but this is an obsolete usage kept for backwards compatibility only.</td> @@ -128,20 +131,20 @@ <td><a href="#python_3000_raise_comma">python_3000_raise_comma</a></td> <td>When raising an exception, use "raise ValueError('message')" instead of the older form "raise ValueError, 'message'".</td> </tr><tr> +<td><a href="#read_config">read_config</a></td> +<td>Read both user configuration and local configuration.</td> +</tr><tr> <td><a href="#readlines">readlines</a></td> <td></td> </tr><tr> <td><a href="#readlines_1">readlines</a></td> <td></td> </tr><tr> -<td><a href="#reset_counters">reset_counters</a></td> -<td></td> +<td><a href="#register_check">register_check</a></td> +<td>Register a new check object.</td> </tr><tr> -<td><a href="#run_tests">run_tests</a></td> -<td>Run all the tests from a file.</td> -</tr><tr> -<td><a href="#selftest">selftest</a></td> -<td>Test all check functions with test cases in docstrings.</td> +<td><a href="#stdin_get_value">stdin_get_value</a></td> +<td></td> </tr><tr> <td><a href="#tabs_obsolete">tabs_obsolete</a></td> <td></td> @@ -158,6 +161,9 @@ <td><a href="#whitespace_around_comma">whitespace_around_comma</a></td> <td>Avoid extraneous whitespace in the following situations:</td> </tr><tr> +<td><a href="#whitespace_around_keywords">whitespace_around_keywords</a></td> +<td></td> +</tr><tr> <td><a href="#whitespace_around_named_parameter_equals">whitespace_around_named_parameter_equals</a></td> <td>Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.</td> </tr><tr> @@ -172,6 +178,131 @@ </tr> </table> <hr /><hr /> +<a NAME="BaseReport" ID="BaseReport"></a> +<h2>BaseReport</h2> +<p> +Collect the results of the checks. +</p> +<h3>Derived from</h3> +object +<h3>Class Attributes</h3> +<table> +<tr><td>print_filename</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#BaseReport.__init__">BaseReport</a></td> +<td></td> +</tr><tr> +<td><a href="#BaseReport.error">error</a></td> +<td>Report an error, according to options.</td> +</tr><tr> +<td><a href="#BaseReport.error_args">error_args</a></td> +<td>Report an error, according to options.</td> +</tr><tr> +<td><a href="#BaseReport.get_count">get_count</a></td> +<td>Return the total count of errors and warnings.</td> +</tr><tr> +<td><a href="#BaseReport.get_file_results">get_file_results</a></td> +<td>Return the count of errors and warnings for this file.</td> +</tr><tr> +<td><a href="#BaseReport.get_statistics">get_statistics</a></td> +<td>Get statistics for message codes that start with the prefix.</td> +</tr><tr> +<td><a href="#BaseReport.increment_logical_line">increment_logical_line</a></td> +<td>Signal a new logical line.</td> +</tr><tr> +<td><a href="#BaseReport.init_file">init_file</a></td> +<td>Signal a new file.</td> +</tr><tr> +<td><a href="#BaseReport.print_benchmark">print_benchmark</a></td> +<td>Print benchmark numbers.</td> +</tr><tr> +<td><a href="#BaseReport.print_statistics">print_statistics</a></td> +<td>Print overall statistics (number of errors and warnings).</td> +</tr><tr> +<td><a href="#BaseReport.start">start</a></td> +<td>Start the timer.</td> +</tr><tr> +<td><a href="#BaseReport.stop">stop</a></td> +<td>Stop the timer.</td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="BaseReport.__init__" ID="BaseReport.__init__"></a> +<h4>BaseReport (Constructor)</h4> +<b>BaseReport</b>(<i>options</i>) +<a NAME="BaseReport.error" ID="BaseReport.error"></a> +<h4>BaseReport.error</h4> +<b>error</b>(<i>line_number, offset, text, check</i>) +<p> +Report an error, according to options. +</p><a NAME="BaseReport.error_args" ID="BaseReport.error_args"></a> +<h4>BaseReport.error_args</h4> +<b>error_args</b>(<i>line_number, offset, code, check, *args</i>) +<p> +Report an error, according to options. +</p><a NAME="BaseReport.get_count" ID="BaseReport.get_count"></a> +<h4>BaseReport.get_count</h4> +<b>get_count</b>(<i>prefix=''</i>) +<p> +Return the total count of errors and warnings. +</p><a NAME="BaseReport.get_file_results" ID="BaseReport.get_file_results"></a> +<h4>BaseReport.get_file_results</h4> +<b>get_file_results</b>(<i></i>) +<p> +Return the count of errors and warnings for this file. +</p><a NAME="BaseReport.get_statistics" ID="BaseReport.get_statistics"></a> +<h4>BaseReport.get_statistics</h4> +<b>get_statistics</b>(<i>prefix=''</i>) +<p> + Get statistics for message codes that start with the prefix. +</p><p> + prefix='' matches all errors and warnings + prefix='E' matches all errors + prefix='W' matches all warnings + prefix='E4' matches all errors that have to do with imports +</p><a NAME="BaseReport.increment_logical_line" ID="BaseReport.increment_logical_line"></a> +<h4>BaseReport.increment_logical_line</h4> +<b>increment_logical_line</b>(<i></i>) +<p> +Signal a new logical line. +</p><a NAME="BaseReport.init_file" ID="BaseReport.init_file"></a> +<h4>BaseReport.init_file</h4> +<b>init_file</b>(<i>filename, lines, expected, line_offset</i>) +<p> +Signal a new file. +</p><a NAME="BaseReport.print_benchmark" ID="BaseReport.print_benchmark"></a> +<h4>BaseReport.print_benchmark</h4> +<b>print_benchmark</b>(<i></i>) +<p> +Print benchmark numbers. +</p><a NAME="BaseReport.print_statistics" ID="BaseReport.print_statistics"></a> +<h4>BaseReport.print_statistics</h4> +<b>print_statistics</b>(<i>prefix=''</i>) +<p> +Print overall statistics (number of errors and warnings). +</p><a NAME="BaseReport.start" ID="BaseReport.start"></a> +<h4>BaseReport.start</h4> +<b>start</b>(<i></i>) +<p> +Start the timer. +</p><a NAME="BaseReport.stop" ID="BaseReport.stop"></a> +<h4>BaseReport.stop</h4> +<b>stop</b>(<i></i>) +<p> +Stop the timer. +</p> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> <a NAME="Checker" ID="Checker"></a> <h2>Checker</h2> <p> @@ -199,20 +330,26 @@ <td><a href="#Checker.check_all">check_all</a></td> <td>Run all checks on the input file.</td> </tr><tr> +<td><a href="#Checker.check_ast">check_ast</a></td> +<td></td> +</tr><tr> <td><a href="#Checker.check_logical">check_logical</a></td> <td>Build a line from tokens and run all logical checks on it.</td> </tr><tr> <td><a href="#Checker.check_physical">check_physical</a></td> <td>Run all physical checks on a raw input line.</td> </tr><tr> +<td><a href="#Checker.generate_tokens">generate_tokens</a></td> +<td></td> +</tr><tr> <td><a href="#Checker.readline">readline</a></td> <td>Get the next line from the input buffer.</td> </tr><tr> <td><a href="#Checker.readline_check_physical">readline_check_physical</a></td> <td>Check and return the next physical line.</td> </tr><tr> -<td><a href="#Checker.report_error">report_error</a></td> -<td>Report an error, according to options.</td> +<td><a href="#Checker.report_invalid_syntax">report_invalid_syntax</a></td> +<td></td> </tr><tr> <td><a href="#Checker.run_check">run_check</a></td> <td>Run a check plugin.</td> @@ -224,7 +361,7 @@ </table> <a NAME="Checker.__init__" ID="Checker.__init__"></a> <h4>Checker (Constructor)</h4> -<b>Checker</b>(<i>filename, lines=None</i>) +<b>Checker</b>(<i>filename=None, lines=None, options=None, report=None, **kwargs</i>) <a NAME="Checker.build_tokens_line" ID="Checker.build_tokens_line"></a> <h4>Checker.build_tokens_line</h4> <b>build_tokens_line</b>(<i></i>) @@ -235,7 +372,10 @@ <b>check_all</b>(<i>expected=None, line_offset=0</i>) <p> Run all checks on the input file. -</p><a NAME="Checker.check_logical" ID="Checker.check_logical"></a> +</p><a NAME="Checker.check_ast" ID="Checker.check_ast"></a> +<h4>Checker.check_ast</h4> +<b>check_ast</b>(<i></i>) +<a NAME="Checker.check_logical" ID="Checker.check_logical"></a> <h4>Checker.check_logical</h4> <b>check_logical</b>(<i></i>) <p> @@ -245,7 +385,10 @@ <b>check_physical</b>(<i>line</i>) <p> Run all physical checks on a raw input line. -</p><a NAME="Checker.readline" ID="Checker.readline"></a> +</p><a NAME="Checker.generate_tokens" ID="Checker.generate_tokens"></a> +<h4>Checker.generate_tokens</h4> +<b>generate_tokens</b>(<i></i>) +<a NAME="Checker.readline" ID="Checker.readline"></a> <h4>Checker.readline</h4> <b>readline</b>(<i></i>) <p> @@ -256,12 +399,10 @@ <p> Check and return the next physical line. This method can be used to feed tokenize.generate_tokens. -</p><a NAME="Checker.report_error" ID="Checker.report_error"></a> -<h4>Checker.report_error</h4> -<b>report_error</b>(<i>line_number, offset, text, check</i>) -<p> - Report an error, according to options. -</p><a NAME="Checker.run_check" ID="Checker.run_check"></a> +</p><a NAME="Checker.report_invalid_syntax" ID="Checker.report_invalid_syntax"></a> +<h4>Checker.report_invalid_syntax</h4> +<b>report_invalid_syntax</b>(<i></i>) +<a NAME="Checker.run_check" ID="Checker.run_check"></a> <h4>Checker.run_check</h4> <b>run_check</b>(<i>check, argument_names</i>) <p> @@ -269,52 +410,306 @@ </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> +<a NAME="DiffReport" ID="DiffReport"></a> +<h2>DiffReport</h2> +<p> +Collect and print the results for the changed lines only. +</p> +<h3>Derived from</h3> +StandardReport +<h3>Class Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#DiffReport.__init__">DiffReport</a></td> +<td></td> +</tr><tr> +<td><a href="#DiffReport.error">error</a></td> +<td></td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="DiffReport.__init__" ID="DiffReport.__init__"></a> +<h4>DiffReport (Constructor)</h4> +<b>DiffReport</b>(<i>options</i>) +<a NAME="DiffReport.error" ID="DiffReport.error"></a> +<h4>DiffReport.error</h4> +<b>error</b>(<i>line_number, offset, text, check</i>) + +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="FileReport" ID="FileReport"></a> +<h2>FileReport</h2> +<p> +Collect the results of the checks and print only the filenames. +</p> +<h3>Derived from</h3> +BaseReport +<h3>Class Attributes</h3> +<table> +<tr><td>print_filename</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> + +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="StandardReport" ID="StandardReport"></a> +<h2>StandardReport</h2> +<p> +Collect and print the results of the checks. +</p> +<h3>Derived from</h3> +BaseReport +<h3>Class Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#StandardReport.__init__">StandardReport</a></td> +<td></td> +</tr><tr> +<td><a href="#StandardReport.error">error</a></td> +<td>Report an error, according to options.</td> +</tr><tr> +<td><a href="#StandardReport.error_args">error_args</a></td> +<td>Report an error, according to options.</td> +</tr><tr> +<td><a href="#StandardReport.get_file_results">get_file_results</a></td> +<td>Print the result and return the overall count for this file.</td> +</tr><tr> +<td><a href="#StandardReport.init_file">init_file</a></td> +<td>Signal a new file.</td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="StandardReport.__init__" ID="StandardReport.__init__"></a> +<h4>StandardReport (Constructor)</h4> +<b>StandardReport</b>(<i>options</i>) +<a NAME="StandardReport.error" ID="StandardReport.error"></a> +<h4>StandardReport.error</h4> +<b>error</b>(<i>line_number, offset, text, check</i>) +<p> +Report an error, according to options. +</p><a NAME="StandardReport.error_args" ID="StandardReport.error_args"></a> +<h4>StandardReport.error_args</h4> +<b>error_args</b>(<i>line_number, offset, code, check, *args</i>) +<p> +Report an error, according to options. +</p><a NAME="StandardReport.get_file_results" ID="StandardReport.get_file_results"></a> +<h4>StandardReport.get_file_results</h4> +<b>get_file_results</b>(<i></i>) +<p> +Print the result and return the overall count for this file. +</p><a NAME="StandardReport.init_file" ID="StandardReport.init_file"></a> +<h4>StandardReport.init_file</h4> +<b>init_file</b>(<i>filename, lines, expected, line_offset</i>) +<p> +Signal a new file. +</p> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="StyleGuide" ID="StyleGuide"></a> +<h2>StyleGuide</h2> +<p> +Initialize a PEP-8 instance with few options. +</p> +<h3>Derived from</h3> +object +<h3>Class Attributes</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Class Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<h3>Methods</h3> +<table> +<tr> +<td><a href="#StyleGuide.__init__">StyleGuide</a></td> +<td></td> +</tr><tr> +<td><a href="#StyleGuide.check_files">check_files</a></td> +<td>Run all checks on the paths.</td> +</tr><tr> +<td><a href="#StyleGuide.excluded">excluded</a></td> +<td>Check if options.exclude contains a pattern that matches filename.</td> +</tr><tr> +<td><a href="#StyleGuide.get_checks">get_checks</a></td> +<td>Find all globally visible functions where the first argument name starts with argument_name and which contain selected tests.</td> +</tr><tr> +<td><a href="#StyleGuide.ignore_code">ignore_code</a></td> +<td>Check if the error code should be ignored.</td> +</tr><tr> +<td><a href="#StyleGuide.init_report">init_report</a></td> +<td>Initialize the report instance.</td> +</tr><tr> +<td><a href="#StyleGuide.input_dir">input_dir</a></td> +<td>Check all files in this directory and all subdirectories.</td> +</tr><tr> +<td><a href="#StyleGuide.input_file">input_file</a></td> +<td>Run all checks on a Python source file.</td> +</tr> +</table> +<h3>Static Methods</h3> +<table> +<tr><td>None</td></tr> +</table> +<a NAME="StyleGuide.__init__" ID="StyleGuide.__init__"></a> +<h4>StyleGuide (Constructor)</h4> +<b>StyleGuide</b>(<i>*args, **kwargs</i>) +<a NAME="StyleGuide.check_files" ID="StyleGuide.check_files"></a> +<h4>StyleGuide.check_files</h4> +<b>check_files</b>(<i>paths=None</i>) +<p> +Run all checks on the paths. +</p><a NAME="StyleGuide.excluded" ID="StyleGuide.excluded"></a> +<h4>StyleGuide.excluded</h4> +<b>excluded</b>(<i>filename, parent=None</i>) +<p> + Check if options.exclude contains a pattern that matches filename. +</p><a NAME="StyleGuide.get_checks" ID="StyleGuide.get_checks"></a> +<h4>StyleGuide.get_checks</h4> +<b>get_checks</b>(<i>argument_name</i>) +<p> + Find all globally visible functions where the first argument name + starts with argument_name and which contain selected tests. +</p><a NAME="StyleGuide.ignore_code" ID="StyleGuide.ignore_code"></a> +<h4>StyleGuide.ignore_code</h4> +<b>ignore_code</b>(<i>code</i>) +<p> + Check if the error code should be ignored. +</p><p> + If 'options.select' contains a prefix of the error code, + return False. Else, if 'options.ignore' contains a prefix of + the error code, return True. +</p><a NAME="StyleGuide.init_report" ID="StyleGuide.init_report"></a> +<h4>StyleGuide.init_report</h4> +<b>init_report</b>(<i>reporter=None</i>) +<p> +Initialize the report instance. +</p><a NAME="StyleGuide.input_dir" ID="StyleGuide.input_dir"></a> +<h4>StyleGuide.input_dir</h4> +<b>input_dir</b>(<i>dirname</i>) +<p> +Check all files in this directory and all subdirectories. +</p><a NAME="StyleGuide.input_file" ID="StyleGuide.input_file"></a> +<h4>StyleGuide.input_file</h4> +<b>input_file</b>(<i>filename, lines=None, expected=None, line_offset=0</i>) +<p> +Run all checks on a Python source file. +</p> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="_add_check" ID="_add_check"></a> +<h2>_add_check</h2> +<b>_add_check</b>(<i>check, kind, codes, args</i>) + +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> <a NAME="_main" ID="_main"></a> <h2>_main</h2> <b>_main</b>(<i></i>) <p> - Parse options and run checks on Python source. +Parse options and run checks on Python source. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="blank_lines" ID="blank_lines"></a> <h2>blank_lines</h2> -<b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level, blank_lines_before_comment</i>) +<b>blank_lines</b>(<i>logical_line, blank_lines, indent_level, line_number, previous_logical, previous_indent_level</i>) <div align="right"><a href="#top">Up</a></div> <hr /><hr /> +<a NAME="comparison_to_singleton" ID="comparison_to_singleton"></a> +<h2>comparison_to_singleton</h2> +<b>comparison_to_singleton</b>(<i>logical_line, noqa</i>) +<p> + Comparisons to singletons like None should always be done + with "is" or "is not", never the equality operators. +</p><p> + Okay: if arg is not None: + E711: if arg != None: + E712: if arg == True: +</p><p> + Also, beware of writing if x when you really mean if x is not None -- + e.g. when testing whether a variable or argument that defaults to None was + set to some other value. The other value might have a type (such as a + container) that could be false in a boolean context! +</p> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="comparison_type" ID="comparison_type"></a> +<h2>comparison_type</h2> +<b>comparison_type</b>(<i>logical_line</i>) +<p> + Object type comparisons should always use isinstance() instead of + comparing types directly. +</p><p> + Okay: if isinstance(obj, int): + E721: if type(obj) is type(1): +</p><p> + When checking if an object is a string, keep in mind that it might be a + unicode string too! In Python 2.3, str and unicode have a common base + class, basestring, so you can do: +</p><p> + Okay: if isinstance(obj, basestring): + Okay: if type(a1) is type(b1): +</p> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> <a NAME="compound_statements" ID="compound_statements"></a> <h2>compound_statements</h2> <b>compound_statements</b>(<i>logical_line</i>) <div align="right"><a href="#top">Up</a></div> <hr /><hr /> -<a NAME="excluded" ID="excluded"></a> -<h2>excluded</h2> -<b>excluded</b>(<i>filename</i>) -<p> - Check if options.exclude contains a pattern that matches filename. -</p> +<a NAME="continued_indentation" ID="continued_indentation"></a> +<h2>continued_indentation</h2> +<b>continued_indentation</b>(<i>logical_line, tokens, indent_level, hang_closing, noqa, verbose</i>) + <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="expand_indent" ID="expand_indent"></a> <h2>expand_indent</h2> <b>expand_indent</b>(<i>line</i>) -<p> - Return the amount of indentation. - Tabs are expanded to the next multiple of 8. -</p><p> - >>> expand_indent(' ') - 4 - >>> expand_indent('\\t') - 8 - >>> expand_indent(' \\t') - 8 - >>> expand_indent(' \\t') - 8 - >>> expand_indent(' \\t') - 16 -</p> + +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="explicit_line_join" ID="explicit_line_join"></a> +<h2>explicit_line_join</h2> +<b>explicit_line_join</b>(<i>logical_line, tokens</i>) + <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="extraneous_whitespace" ID="extraneous_whitespace"></a> @@ -343,19 +738,10 @@ <hr /><hr /> <a NAME="filename_match" ID="filename_match"></a> <h2>filename_match</h2> -<b>filename_match</b>(<i>filename</i>) +<b>filename_match</b>(<i>filename, patterns, default=True</i>) <p> - Check if options.filename contains a pattern that matches filename. - If options.filename is unspecified, this always returns True. -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="find_checks" ID="find_checks"></a> -<h2>find_checks</h2> -<b>find_checks</b>(<i>argument_name</i>) -<p> - Find all globally visible functions where the first argument name - starts with argument_name. + Check if patterns contains a pattern that matches filename. + If patterns is unspecified, this always returns True. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> @@ -380,50 +766,10 @@ </dl> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> -<a NAME="get_count" ID="get_count"></a> -<h2>get_count</h2> -<b>get_count</b>(<i>prefix=''</i>) -<p> -Return the total count of errors and warnings. -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="get_error_statistics" ID="get_error_statistics"></a> -<h2>get_error_statistics</h2> -<b>get_error_statistics</b>(<i></i>) -<p> -Get error statistics. -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="get_statistics" ID="get_statistics"></a> -<h2>get_statistics</h2> -<b>get_statistics</b>(<i>prefix=''</i>) -<p> - Get statistics for message codes that start with the prefix. -</p><p> - prefix='' matches all errors and warnings - prefix='E' matches all errors - prefix='W' matches all warnings - prefix='E4' matches all errors that have to do with imports -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="get_warning_statistics" ID="get_warning_statistics"></a> -<h2>get_warning_statistics</h2> -<b>get_warning_statistics</b>(<i></i>) -<p> -Get warning statistics. -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="ignore_code" ID="ignore_code"></a> -<h2>ignore_code</h2> -<b>ignore_code</b>(<i>code</i>) -<p> - Check if options.ignore contains a prefix of the error code. - If options.select contains a prefix of the error code, do not ignore it. -</p> +<a NAME="get_parser" ID="get_parser"></a> +<h2>get_parser</h2> +<b>get_parser</b>(<i>prog='pep8', version=__version__</i>) + <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="imports_on_separate_lines" ID="imports_on_separate_lines"></a> @@ -438,25 +784,18 @@ <div align="right"><a href="#top">Up</a></div> <hr /><hr /> -<a NAME="input_dir" ID="input_dir"></a> -<h2>input_dir</h2> -<b>input_dir</b>(<i>dirname, runner=None</i>) +<a NAME="init_checks_registry" ID="init_checks_registry"></a> +<h2>init_checks_registry</h2> +<b>init_checks_registry</b>(<i></i>) <p> - Check all Python source files in this directory and all subdirectories. -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="input_file" ID="input_file"></a> -<h2>input_file</h2> -<b>input_file</b>(<i>filename</i>) -<p> - Run all checks on a Python source file. + Register all globally visible functions where the first argument name + is 'physical_line' or 'logical_line'. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="maximum_line_length" ID="maximum_line_length"></a> <h2>maximum_line_length</h2> -<b>maximum_line_length</b>(<i>physical_line</i>) +<b>maximum_line_length</b>(<i>physical_line, max_line_length</i>) <p> Limit all lines to a maximum of 79 characters. </p><p> @@ -466,14 +805,8 @@ ugly. Therefore, please limit all lines to a maximum of 79 characters. For flowing long blocks of text (docstrings or comments), limiting the length to 72 characters is recommended. -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="message" ID="message"></a> -<h2>message</h2> -<b>message</b>(<i>text</i>) -<p> -Print a message. +</p><p> + Reports error E501. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> @@ -482,6 +815,8 @@ <b>missing_newline</b>(<i>physical_line</i>) <p> JCR: The last line should have a newline. +</p><p> + Reports warning W292. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> @@ -499,6 +834,7 @@ Okay: a[1:4:2] E231: ['a','b'] E231: foo(bar,baz) + E231: [{'a':'b'}] </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> @@ -523,27 +859,19 @@ </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> -<a NAME="print_benchmark" ID="print_benchmark"></a> -<h2>print_benchmark</h2> -<b>print_benchmark</b>(<i>elapsed</i>) +<a NAME="parse_udiff" ID="parse_udiff"></a> +<h2>parse_udiff</h2> +<b>parse_udiff</b>(<i>diff, patterns=None, parent='.'</i>) <p> - Print benchmark numbers. -</p> -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="print_statistics" ID="print_statistics"></a> -<h2>print_statistics</h2> -<b>print_statistics</b>(<i>prefix=''</i>) -<p> -Print overall statistics (number of errors and warnings). +Return a dictionary of matching lines. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="process_options" ID="process_options"></a> <h2>process_options</h2> -<b>process_options</b>(<i>arglist=None</i>) +<b>process_options</b>(<i>arglist=None, parse_argv=False, config_file=None, parser=None</i>) <p> - Process options passed either via arglist or via command line args. +Process options passed either via arglist or via command line args. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> @@ -551,21 +879,18 @@ <h2>python_3000_backticks</h2> <b>python_3000_backticks</b>(<i>logical_line</i>) <p> - Backticks are removed in Python 3000. + Backticks are removed in Python 3. Use repr() instead. +</p><p> + Okay: val = repr(1 + 2) + W604: val = `1 + 2` </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="python_3000_has_key" ID="python_3000_has_key"></a> <h2>python_3000_has_key</h2> <b>python_3000_has_key</b>(<i>logical_line</i>) -<p> - The {}.has_key() method will be removed in the future version of - Python. Use the 'in' operation instead, like: - d = {"a": 1, "b": 2} - if "b" in d: - print d["b"] -</p> + <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="python_3000_not_equal" ID="python_3000_not_equal"></a> @@ -574,7 +899,10 @@ <p> != can also be written <>, but this is an obsolete usage kept for backwards compatibility only. New code should always use !=. - The older syntax is removed in Python 3000. + The older syntax is removed in Python 3. +</p><p> + Okay: if a != 'no': + W603: if a <> 'no': </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> @@ -588,7 +916,18 @@ The paren-using form is preferred because when the exception arguments are long or include string formatting, you don't need to use line continuation characters thanks to the containing parentheses. The older - form will be removed in Python 3000. + form is removed in Python 3. +</p><p> + Okay: raise DummyError("Message") + W602: raise DummyError, "Message" +</p> +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> +<a NAME="read_config" ID="read_config"></a> +<h2>read_config</h2> +<b>read_config</b>(<i>options, args, arglist, parser</i>) +<p> +Read both user configuration and local configuration. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> @@ -604,40 +943,18 @@ <div align="right"><a href="#top">Up</a></div> <hr /><hr /> -<a NAME="reset_counters" ID="reset_counters"></a> -<h2>reset_counters</h2> -<b>reset_counters</b>(<i></i>) - -<div align="right"><a href="#top">Up</a></div> -<hr /><hr /> -<a NAME="run_tests" ID="run_tests"></a> -<h2>run_tests</h2> -<b>run_tests</b>(<i>filename</i>) +<a NAME="register_check" ID="register_check"></a> +<h2>register_check</h2> +<b>register_check</b>(<i>check, codes=None</i>) <p> - Run all the tests from a file. -</p><p> - A test file can provide many tests. Each test starts with a declaration. - This declaration is a single line starting with '#:'. - It declares codes of expected failures, separated by spaces or 'Okay' - if no failure is expected. - If the file does not contain such declaration, it should pass all tests. - If the declaration is empty, following lines are not checked, until next - declaration. -</p><p> - Examples: -</p><p> - * Only E224 and W701 are expected: #: E224 W701 - * Following example is conform: #: Okay - * Don't check these lines: #: + Register a new check object. </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> -<a NAME="selftest" ID="selftest"></a> -<h2>selftest</h2> -<b>selftest</b>(<i></i>) -<p> - Test all check functions with test cases in docstrings. -</p> +<a NAME="stdin_get_value" ID="stdin_get_value"></a> +<h2>stdin_get_value</h2> +<b>stdin_get_value</b>(<i></i>) + <div align="right"><a href="#top">Up</a></div> <hr /><hr /> <a NAME="tabs_obsolete" ID="tabs_obsolete"></a> @@ -682,9 +999,15 @@ </p> <div align="right"><a href="#top">Up</a></div> <hr /><hr /> +<a NAME="whitespace_around_keywords" ID="whitespace_around_keywords"></a> +<h2>whitespace_around_keywords</h2> +<b>whitespace_around_keywords</b>(<i>logical_line</i>) + +<div align="right"><a href="#top">Up</a></div> +<hr /><hr /> <a NAME="whitespace_around_named_parameter_equals" ID="whitespace_around_named_parameter_equals"></a> <h2>whitespace_around_named_parameter_equals</h2> -<b>whitespace_around_named_parameter_equals</b>(<i>logical_line</i>) +<b>whitespace_around_named_parameter_equals</b>(<i>logical_line, tokens</i>) <p> Don't use spaces around the '=' sign when used to indicate a keyword argument or a default parameter value.