terrencepreilly / darglint

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

Stray `DAR003` issue when using sphinx type docstring #172

Open agatti opened 3 years ago

agatti commented 3 years ago

Similar to #117, on darglint 1.8.0 I am getting a DAR003 issue on a docstring that does not look like has anything strange going for it and I am wondering what I am doing wrong with that. The code fragment is as follows:


@pytest.fixture(scope="session")
def ssh_output_path() -> Path:
    """Return the common path for output files created from tests.

    :returns: the output directory.
    :raise FileNotFoundError: if the found path does not exist.
    :raise NotADirectoryError: if the found path is not a directory.
    """

    path = Path("testoutput") / "test"
    check_directory_path(path)
    return path

and I also checked that there isn't any other spurious whitespace lingering around:

Screenshot 2021-07-23 at 01 17 16

The darglint configuration is set to default except for the docstring style being sphinx and strictness being set to full.

Interestingly the error message occurs on the first :raise line, with the same description as #117, "Incorrect indentation: ~<":


   205:   1 DAR003 Incorrect indentation: ~< [flake8-darglint]
  """Return the common path for output files created from tests.

    :returns: the output directory.
    :raise FileNotFoundError: if the found path does not exist.
    :raise NotADirectoryError: if the found path is not a directory.
    """
  ^

Is there anything else I can try to see if this can be sorted out?

Thanks!

webknjaz commented 2 years ago

@agatti is it :raise: or :raises:? I think it should be the latter.

sziem commented 2 years ago

Thanks @webknjaz ! I just ran into the exact same issue, after writing :raise: instead of :raises: and was about to add an "ignore" comment, before I read your comment.

The confusing thing for me is that there appears to be some inconsistency between my pycharm editor and darglint linting.

The raise keyword is highlighted by pycharm as if it were a valid keyword, but darglint complains about it image

$ flake8 src/man_adt/evaluation_utils/entrypoints/flake8.py 
src/man_adt/evaluation_utils/entrypoints/flake8.py:5:1: DAR401 Missing exception(s) in Raises section: -r ValueError
src/man_adt/evaluation_utils/entrypoints/flake8.py:8:1: DAR003 Incorrect indentation: ~<

I'm not an expert on docstrings, so I am not really sure, whether or under which conditions raise (without s) is actually valid. But in my case this compiles succesfully with sphinx.

cthoyt commented 2 years ago

You might be missing some darglint configuration to tell it to use sphinx-style docs. Put this in you setup.cfg or darglint config file:

[darglint]
docstring_style = sphinx