terrencepreilly / darglint

A python documentation linter which checks that the docstring description matches the definition.
MIT License
481 stars 41 forks source link

Why doesn't darglint recognize PyPDF2 Sphinx-style docstrings? #202

Closed MartinThoma closed 2 years ago

MartinThoma commented 2 years ago

I'm currently adding type annotations for PyPDF2 (PR) and I check with mypy + typeguard if the types I add make sense.

I would also like to check with darglint if the docstrings are good. However, darglint seems not to recongize anything. Take this for example:

    def addBookmark(
        self,
        title: str,
        pagenum: int,
        parent: Union[None, TreeObject, IndirectObject] = None,
        color: Optional[Tuple[float, float, float]] = None,
        bold: bool = False,
        italic: bool = False,
        fit: str = "/Fit",
        *args: ZoomArgType
    ) -> IndirectObject:
        """
        Add a bookmark to this PDF file.

        :param str title: Title to use for this bookmark.
        :param int pagenum: Page number this bookmark will point to.
        :param parent: A reference to a parent bookmark to create nested
            bookmarks.
        :param tuple color: Color of the bookmark as a red, green, blue tuple
            from 0.0 to 1.0
        :param bool bold: Bookmark is bold
        :param bool italic: Bookmark is italic
        :param str fit: The fit of the destination page. See
            :meth:`addLink()<addLin>` for details.
        """
    ...

Sphinx renders it fine. Why does darglint still tell me the following?

$ darglint -s numpy --ignore-raise RuntimeError PyPDF2/
[...]
PyPDF2/merger.py:addBookmark:577: DAR101: - *args
PyPDF2/merger.py:addBookmark:577: DAR101: - bold
PyPDF2/merger.py:addBookmark:577: DAR101: - color
PyPDF2/merger.py:addBookmark:577: DAR101: - fit
PyPDF2/merger.py:addBookmark:577: DAR101: - italic
PyPDF2/merger.py:addBookmark:577: DAR101: - pagenum
PyPDF2/merger.py:addBookmark:577: DAR101: - parent
PyPDF2/merger.py:addBookmark:577: DAR201: - return
PyPDF2/merger.py:addBookmark:577: DAR101: - title
terrencepreilly commented 2 years ago

See https://github.com/terrencepreilly/darglint#type-annotations. In particular,

Darglint only accepts types accepted by Python (see PEP 484.) That is, it does not accept parentheses in type signatures. (If parentheses are used in the type signature, Darglint will mark that argument as missing. See Issue #90.)

So types like tuple won't work. You're also calling this with the numpy parser, not Sphinx.

Having types in the documentation and types in the annotations is a little redundant, unless you're trying to transition a codebase to using type annotations. It would probably be better to just leave them out if you can.