These rules extend and override the general rules.

We respect PEP8 unless we have a good reason for not following it. For doc blocks we use Google’s version of reStructuredText.

Tooling

Flake8 is a code quality tool which enforces the PEP8 standard. You can install it globally using

pip install flake8

After that, make sure to install a plugin so your editor automatically checks files for you.

The only exception to the base flake8 rules is the line length, which we set to 120 instead of the default 80. You can configure this by editing/creating ~/.config/flake8 and changing the contents to contain this:

[flake8]
max-line-length = 120

Specific Constructs

Use new style classes. They come with new functionality and it makes the code base predictable for other developers

# Note the "(object)" part. This is what makes it a new style class.
class MyClass(object):

Use string.format. It is the way the language is moving.

"Hello, {0}".format(person)

Use double quotes (“).

Avoid dictionary comprehension. It is not available in python 2.6. List comprehensions are ok.

Do not use string.format without defining an index for a parameter.

# Note the "0". This must exist in order to work with python 2.6.6
"Hello, {0}".format(person)

When wrapping parameters on separate lines, put each parameter on its own line and outdent the ending parenthesis to match the start of the original line.

my_func_with_lots_of_parameters(
    param1,
    param2,
    param3,
    param4
)