python-security/pyt

Add docstrings to everything

Open

#109 opened on 2018年4月15日

GitHub で見る
 (0 comments) (0 reactions) (0 assignees)Python (2,141 stars) (259 forks)batch import
epicgood first issuehelp wanted

説明

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.

コントリビューターガイド