Code Style

We use YAPF to check Python code style and apply automatic formatting.

Code should conform to PEP8, the style guide for Python code. YAPF goes beyond that and applies stylistic changes as configured in the style file .style.yapf. Our maximal line length is 120.

Auto-Formatting Python Code

Running yapf -dr src shows a diff for the entire source directory. yapf -ir src formats everything in-place (git commit first!).

An alias to auto-format only changed files as seen by Git may be helpful:

alias py-format-changed="git ls-files -m --others --exclude-standard | grep '\.py$' | xargs yapf -i"

Style Tips

If you want each list value to stay on a separate line, use a trailing comma after the last element (here after 'created_at'):

model_properties = [
    'abstract',
    'author',
    'ballot',
    'content',
    'created_at',
]