pyt icon indicating copy to clipboard operation
pyt copied to clipboard

Add docstrings to everything

Open KevinHock opened this issue 7 years ago • 0 comments

You can do:

pip install pydocstyle and then run this script while in the pyt directory

import os
import re
import subprocess
import sys


os.chdir(os.path.join('pyt'))

try:
    docstyle = subprocess.run(["pydocstyle", "--ignore=D105,D203,D212,D213"],
                              stderr=subprocess.PIPE, universal_newlines=True)
except FileNotFoundError:
    print('Error: Install pydocstyle with pip for python 3.'
          ' Something like: "sudo python -m pip install pydocstyle"')
    sys.exit()

lines = re.split('\n', docstyle.stderr)

errors = zip(lines[0::2], lines[1::2])

errors = [x + "\n\t" + y for x, y in errors]

errors = [error for error in errors if 'visit_' not in error]

for error in errors:
    print(error + '\n')

print("Total errors: {}".format(len(errors)))

It'll spit out which functions don't have docstrings or complain about something non-PEP 257 compliant.

This is a great way to learn the codebase, and everyone will love you for it.

The imports code for example does not have docstrings, for example.

For an example of great docstrings, see the user-defined function calls code.

Afterwards, we can maybe add it as a pre-commit hook.

KevinHock avatar Apr 15 '18 00:04 KevinHock