This lesson is part of the Automating Python Code Quality course.
In this lesson, you will learn,
- what pydocstyle is
- how to install pydocstyle
- how to validate your docstrings using pydocstyle
- pydocstyle's main configuration options.
What is pydocstyle?
pydocstyle is a linting tool that validates that your Python docstrings are compliant with PEP257 - for example, that the right type of quotes are used or if no docstrings have even been added at all.
How to Install pydocstyle
To install pydocstyle we just run:
$ poetry add -D pydocstyle
Usage
pydocstyle can be run against a file or directory. If a directory is specified, pydocstyle will recursively check all of the files. Examples of each are shown below:
$ pydocstyle .
$ pydocstyle dir
$ pydocstyle myfile.py
Therefore, let’s say we have the following file:
❯ cat 002_linting/003_pydocstyle_issues.py
def get_vlan():
return {
100: "VLAN100"
}
def get_asn():
'''Return ASN'''
return {
65400: "ACME lTD"
}