-
Notifications
You must be signed in to change notification settings - Fork 8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Possible false positive for RST203 #17
Comments
It is a pain when different linters give contradictory results. I'm not familiar with https://github.com/terrencepreilly/darglint but it looks like pydocstrings is starting to get similar capabilities via the conventions setting (covering pep256, numpydoc or google style in various levels of completeness). This setting will be available in the next release of the flake8-docstrings plugin, see https://gitlab.com/pycqa/flake8-docstrings/merge_requests/20 What are you using the docstrings with - Sphinx apidoc maybe? Does that give any warning messages one way or the other? That is probably going to be your main concern. This uses docutils internally, but http://rst.ninjs.org agrees with my plugin and wants the blank line otherwise it throws |
Cross reference terrencepreilly/darglint#28 |
Cross reference terrencepreilly/darglint#56 |
The underlying issue appears to be that So it seems to me that this issue is in fact unrelated to Darglint, and the behavior of |
Thanks you @cjolowicz for that analysis. I hadn't appreciated that Google-style docstrings are not expected to be valid reStructuredText - so in a sense this is means my plugin (flake8-rst-docstrings) is working perfectly. Cross referencing #18, would you say that numpy docstrings are also not expected to be valid reStructuredText (or perhaps valid apart from the use of |
The NumPy docstring standard states that it uses a subset of reStructuredText. IIUC napoleon is not used here to translate a non-RST format to RST, only to enrich the markup in an existing RST document. Looking at the various markup conventions, nothing there strikes me as invalid RST. Escaping asterisks at the start of documented names is probably a good idea, though. |
I had a quick look at how one might preprocess Google docstrings in your plugin. Not sure if it's a good idea, but it could look something like this: from sphinx.ext.napoleon.docstring import GoogleDocstring
def preprocess_google_docstring(text: str, definition: Definition) -> str:
mapping = [
(Module, "module"),
(Class, "class"),
(Method, "method"),
(Function, "function"),
]
for kind, what in mapping:
if isinstance(definition, kind):
break
docstring = GoogleDocstring(text, what=what, name=definition.name)
return str(docstring) This function would be called immediately before invoking You could depend on sphinx via an extra, so only projects using Google docstrings need to install it into the environment they run Flake8 from. One thing the above implementation does not take into account are configuration options for napoleon, and there are probably more rough edges and missing cases. |
That is useful, thank you. You're right that Sphinx / Napoleon settings could be a minefield, probably best avoided. I think we should document that due to pre-processing, Google docstrings are not necessarily valid RST - and specifically suggesting ignoring RST203 "Definition list ends without a blank line; unexpected unindent." as a false positive in this context. |
@peterjc Apparently RST301 "Unexpected indentation" can also be triggered. This happens when the multi-line description is the last function parameter in the Google docstring, see cjolowicz/cookiecutter-hypermodern-python#497. |
Hello @peterjc , Thanks for documenting this in your newest release! I just stumbled onto another "false positive" for Google-style docstrings. There's also the case of a multi-line parameter description surrounded by other parameters: def add(a: int, b: int, c: int) -> int:
"""Add three numbers.
Args:
a: An argument.
b: An argument, which has a description spanning multiple
lines.
c: An argument.
Returns:
The sum.
"""
return a + b + c This results in the following warnings:
Maybe we should advise Google docstring users to ignore You can reproduce this with the following script: #!/bin/bash
virtualenv venv
. venv/bin/activate
pip install flake8-rst-docstrings
flake8 --select RST *.py |
I think the continuation of the "b" argument should be one space less indented, but yes. I think it does make sense to change the README example for Google style to:
Although personally if I would consider this:
|
Thank you! |
I this code that follows google-styleguide: https://google.github.io/styleguide/pyguide.html#doc-function-args
But, I have this violation raised:
But, this is considered valid:
I cannot used this, because it breaks https://github.com/terrencepreilly/darglint
I am not sure what is correct in this case.
The text was updated successfully, but these errors were encountered: