pep8 (version 0.2.0)
index
/home/ut3hax/bin/pep8

Check Python source code formatting, according to PEP 8:
http://www.python.org/dev/peps/pep-0008/
 
For usage and a list of options, try this:
$ python pep8.py -h
 
This program and its regression test suite live here:
http://svn.browsershots.org/trunk/devtools/pep8/
http://trac.browsershots.org/browser/trunk/devtools/pep8/
 
Groups of errors and warnings:
E errors
W warnings
100 indentation
200 whitespace
300 blank lines
400 imports
500 line length
600 deprecation
700 statements
 
You can add checks to this program by writing plugins. Each plugin is
a simple function that is called for each line of source code, either
physical or logical.
 
Physical line:
- Raw line of text from the input file.
 
Logical line:
- Multi-line statements converted to a single line.
- Stripped left and right.
- Contents of strings replaced with 'xxx' of same length.
- Comments removed.
 
The check function requests physical or logical lines by the name of
the first argument:
 
def maximum_line_length(physical_line)
def extraneous_whitespace(logical_line)
def blank_lines(logical_line, blank_lines, indent_level, line_number)
 
The last example above demonstrates how check plugins can request
additional information with extra arguments. All attributes of the
Checker object are available. Some examples:
 
lines: a list of the raw lines from the input file
tokens: the tokens that contribute to this logical line
line_number: line number in the input file
blank_lines: blank lines before this one
indent_char: first indentation character in this file (' ' or ' ')
indent_level: indentation (with tabs expanded to multiples of 8)
previous_indent_level: indentation on previous line
previous_logical: previous logical line
 
The docstring of each check function shall be the relevant part of
text from PEP 8. It is printed if the user enables --show-pep8.

 
Modules
       
inspect
os
re
sys
time
tokenize

 
Classes
       
Checker

 
class Checker
    Load a Python source file, tokenize it, check coding style.
 
  Methods defined here:
__init__(self, filename)
build_tokens_line(self)
Build a logical line from tokens.
check_all(self)
Run all checks on the input file.
check_logical(self)
Build a line from tokens and run all logical checks on it.
check_physical(self, line)
Run all physical checks on a raw input line.
readline(self)
Get the next line from the input buffer.
readline_check_physical(self)
Check and return the next physical line. This method can be
used to feed tokenize.generate_tokens.
report_error(self, line_number, offset, text, check)
Report an error, according to options.
run_check(self, check, argument_names)
Run a check plugin.

 
Functions
       
blank_lines(logical_line, blank_lines, indent_level, line_number, previous_logical)
Separate top-level function and class definitions with two blank lines.
 
Method definitions inside a class are separated by a single blank line.
 
Extra blank lines may be used (sparingly) to separate groups of related
functions.  Blank lines may be omitted between a bunch of related
one-liners (e.g. a set of dummy implementations).
 
Use blank lines in functions, sparingly, to indicate logical sections.
compound_statements(logical_line)
Compound statements (multiple statements on the same line) are
generally discouraged.
excluded(filename)
Check if options.exclude contains a pattern that matches filename.
expand_indent(line)
Return the amount of indentation.
Tabs are expanded to the next multiple of 8.
 
>>> expand_indent('    ')
4
>>> expand_indent('\t')
8
>>> expand_indent('    \t')
8
>>> expand_indent('       \t')
8
>>> expand_indent('        \t')
16
extraneous_whitespace(logical_line)
Avoid extraneous whitespace in the following situations:
 
- Immediately inside parentheses, brackets or braces.
 
- Immediately before a comma, semicolon, or colon.
filename_match(filename)
Check if options.filename contains a pattern that matches filename.
If options.filename is unspecified, this always returns True.
find_checks(argument_name)
Find all globally visible functions where the first argument name
starts with argument_name.
get_error_statistics()
Get error statistics.
get_statistics(prefix='')
Get statistics for message codes that start with the prefix.
 
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
get_warning_statistics()
Get warning statistics.
ignore_code(code)
Check if options.ignore contains a prefix of the error code.
imports_on_separate_lines(logical_line)
Imports should usually be on separate lines.
indent_match = match(...)
match(string[, pos[, endpos]]) --> match object or None.
Matches zero or more characters at the beginning of the string
indentation(logical_line, previous_logical, indent_char, indent_level, previous_indent_level)
Use 4 spaces per indentation level.
 
For really old code that you don't want to mess up, you can continue to
use 8-space tabs.
input_dir(dirname)
Check all Python source files in this directory and all subdirectories.
input_file(filename)
Run all checks on a Python source file.
iskeyword = __contains__(...)
x.__contains__(y) <==> y in x.
maximum_line_length(physical_line)
Limit all lines to a maximum of 79 characters.
 
There are still many devices around that are limited to 80 character
lines; plus, limiting windows to 80 characters makes it possible to have
several windows side-by-side.  The default wrapping on such devices looks
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.
message(text)
Print a message.
missing_newline(physical_line)
JCR: The last line should have a newline.
missing_whitespace(logical_line)
JCR: Each comma, semicolon or colon should be followed by whitespace.
mute_string(text)
Replace contents with 'xxx' to prevent syntax matching.
 
>>> mute_string('"abc"')
'"xxx"'
>>> mute_string("'''abc'''")
"'''xxx'''"
>>> mute_string("r'abc'")
"r'xxx'"
print_benchmark(elapsed)
Print benchmark numbers.
print_statistics(prefix='')
Print overall statistics (number of errors and warnings).
process_options(arglist=None)
Process options passed either via arglist or via command line args.
python_3000_has_key(logical_line)
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"]
python_3000_raise_comma(logical_line)
When raising an exception, use "raise ValueError('message')"
instead of the older form "raise ValueError, 'message'".
 
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.
raise_comma_match = match(...)
match(string[, pos[, endpos]]) --> match object or None.
Matches zero or more characters at the beginning of the string
tabs_obsolete(physical_line)
For new projects, spaces-only are strongly recommended over tabs.  Most
editors have features that make this easy to do.
tabs_or_spaces(physical_line, indent_char)
Never mix tabs and spaces.
 
The most popular way of indenting Python is with spaces only.  The
second-most popular way is with tabs only.  Code indented with a mixture
of tabs and spaces should be converted to using spaces exclusively.  When
invoking the Python command line interpreter with the -t option, it issues
warnings about code that illegally mixes tabs and spaces.  When using -tt
these warnings become errors.  These options are highly recommended!
trailing_blank_lines(physical_line, lines, line_number)
JCR: Trailing blank lines are superfluous.
trailing_whitespace(physical_line)
JCR: Trailing whitespace is superfluous.
whitespace_around_comma(logical_line)
Avoid extraneous whitespace in the following situations:
 
- More than one space around an assignment (or other) operator to
  align it with another.
 
JCR: This should also be applied around comma etc.
whitespace_around_operator(logical_line)
Avoid extraneous whitespace in the following situations:
 
- More than one space around an assignment (or other) operator to
  align it with another.
whitespace_before_parameters(logical_line, tokens)
Avoid extraneous whitespace in the following situations:
 
- Immediately before the open parenthesis that starts the argument
  list of a function call.
 
- Immediately before the open parenthesis that starts an indexing or
  slicing.

 
Data
        __revision__ = '$Rev$'
__version__ = '0.2.0'
args = None
default_exclude = '.svn,CVS,*.pyc,*.pyo'
operators = ['+', '-', '*', '/', '%', '^', '&', '|', '=', '<', '>', '>>', '<<', '+=', '-=', '*=', '/=', '%=', '^=', '&=', ...]
options = None