Skip to content

Code Formatting

Daniel Khashabi edited this page Sep 19, 2017 · 1 revision

Code formatting

yapf

The code formatting tool yapf provides reasonable defaults for code formatting and plenty of knobs to tweak formatting rules for your project. Using it will make your code look consistent, and avoid arguments about formatting in code reviews.

Static code checks

pylint

Using pylint to analyze your code and report irregularities is strongly encouraged.

Within a virtualenv or for python 2:

pip install pylint

For python 3 without virtualenv:

pip3 install pylint

To use:

pylint path/to/python/code/script.py

The warnings can get irritating, so you'll want to learn how to disable some of them in code or in the pylint.rc file. Try searching the relevant github repo for "pylint: disable" to see which warnings are currently considered uninteresting. See https://pylint.readthedocs.io/en/latest/user_guide/message-control.html for more information.

mypy

The mypy tool is an experimental static type checker. It requires python 3.

pip3 install mypy-lang

To use:

mypy path/to/python/code/script.py
Clone this wiki locally