Python guidelines
For any Python code, please stick to the guidelines described in this section.
Python version
For any new projects, please use one of the two most recent Python minor versions. For existing projects, use the Python version used throughout the project.
Code formatting
Please format the code using black
and default parameters. Where
black
is not prescriptive, please use a consistent coding style.
In particular, when contributing to an existing code base, please adhere to the
coding style you find. In all cases, please adhere to PEP 8.
Docstrings
Please add Google-style docstrings to all modules, functions and methods. Follow PEP 257. Do not include types in the docstrings.
Type hints
Add type hints to all function and method signatures, as well as any global variables. Adding type hints to local variables is recommended. Adding type hints to (unit) tests is not necessary.
Linters & static type checkers
Please make use of the following tools with default parameters to make sure your code is of good quality:
When disabling rules is required, it is preferable to do so in-line, rather than globally.
Testing
Use pytest
as a test runner for unit tests. You can determine
the test coverage with the coverage
package. Strive for a test
coverage of 100% for new projects. Proposed code changes should never reduce
the previous test coverage.