Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find undocumented methods in my code?

Tags:

python

pycharm

I am writing documentation for a project and I would like to make sure I did not miss any method. The code is written in Python and I am using PyCharm as an IDE.

Basically, I would need a REGEX to match something like:

def method_name(with, parameters):
    someVar = something()
    ...

but it should NOT match:

def method_name(with, parameters):
    """ The doc string """
    ...

I tried using PyCharm's search with REGEX feature with the pattern ):\s*[^"'] so it would match any line after : that doesn't start with " or ' after whitespace, but it doesn't work. Any idea why?

like image 365
Ciprian Tomoiagă Avatar asked Jun 21 '13 15:06

Ciprian Tomoiagă


2 Answers

You mentioned you were using PyCharm: there is an inspection "Missing, empty, or incorrect docstring" that you can enable and will do that for you.

Note that you can then change the severity for it to show up more or less prominently.

enter image description here

like image 192
Thomas Orozco Avatar answered Oct 24 '22 04:10

Thomas Orozco


There is a tool called pydocstyle which checks if all classes, functions, etc. have properly formatted docstrings.

Example from the README:

$ pydocstyle test.py
test.py:18 in private nested class `meta`:
        D101: Docstring missing
test.py:27 in public function `get_user`:
    D300: Use """triple double quotes""" (found '''-quotes)
test:75 in public function `init_database`:
    D201: No blank lines allowed before function docstring (found 1)

I don't know about PyCharm, but pydocstyle can, for example, be integrated in Vim using the Syntastic plugin.

like image 24
luator Avatar answered Oct 24 '22 02:10

luator