D417 - inconsistent results with Google-style (possible bug) #443
Comments
After further testing, it seems that functions with 2+ parameters have this issue. e.g. if there are 4 parameters and they each start on the next line down, pydocstyle reports D417 for the last 3 and excludes the first parameter. |
Thanks for the detailed bug report, @ColinKennedy! PRs welcome :) |
Thanks @Nurdok I'll give this a try over the weekend. |
I was able to debug this. The error is happening because of the use of |
I don't think I agree with the fact that the above is valid. I can't see any example in the google style guide which suggest that docstrings can start from the next line. I would err on the side of caution. |
Fixed in #448 |
To be fair, I said the same thing in my original post. There's already a precedent for adding docstrings to the next line under. sphinx-napoleon for example is used to add Google-style and numpy support to Sphinx. And numpy already places descriptions under the next line. So I don't see a risk associated with letting Google-style also have the same option. Not to mention, adding "next line" support helps readability when your arguments are verbose. def foo(something=[(8, 1.0), (-1, 11.0), (3, 4, 6, 7)], another_argument=frozenset(), more=None):
"""Do something.
Args:
something (iter[tuple[int, float] or tuple[int]], optional): My information.
another_argument (set[str], optional): Lorem ipsum dolor sit amet, consectetur
adipiscing elit. Ut erat urna, finibus non tincidunt scelerisque, commodo eget ante.
more (None, optional): Aliquam vel justo convallis est sollicitudin egestas et quis arcu.
Nam ut mauris luctus, elementum dolor eu, placerat turpis. Ut non consequat augue,
sit amet dapibus arcu. Vivamus mattis dui vel mi condimentum, pellente
""" versus def foo(something=[(8, 1.0), (-1, 11.0), (3, 4, 6, 7)], another_argument=frozenset(), more=None):
"""Do something.
Args:
something (iter[tuple[int, float] or tuple[int]], optional):
My information.
another_argument (set[str], optional):
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Ut
erat urna, finibus non tincidunt scelerisque, commodo eget ante.
more (None, optional):
Aliquam vel justo convallis est sollicitudin egestas et quis
arcu. Nam ut mauris luctus, elementum dolor eu, placerat
turpis. Ut non consequat augue, sit amet dapibus arcu.
Vivamus mattis dui vel mi condimentum, pellente
""" Keeping the description separate from the variable makes skimming easier. It also makes it easier for auto-formatting tools like par do its work to keep within PEP8's 79 characters. If needed, I can make a separate issue/pull request so we can keep this one just related to the original bug. |
Thanks, that would be great. I think it would be better to know what's the general opinion on this before implementing it. |
Copying from Google style guide -
http://google.github.io/styleguide/pyguide.html#383-functions-and-methods |
Oh nice, thank you for the link @samj1912 . It's good to see that Google thought of this in advance. I'll go ahead and make that separate ticket |
Currently, due to the way the regex was specified, the regex matcher was getting thrown off by types that used colons. This change makes the regex robust to such type and fixes PyCQA#443
Currently, due to the way the regex was specified, the regex matcher was getting thrown off by types that used colons. This change makes the regex robust to such type and fixes #443
D417 does not report for all parameters in a function docstring. Take this example file, below.
Results
When I ran pydocstyle, it only complains with
This strikes me as inconsistent. The
verbose
parameter inbar
is considered valid because its description starts on the same line as the parameter.skips
doesn't start on the same line of the parameter in bothfoo
andbar
but pydocstyle doesn't ever complain aboutskips
. It only seems to care aboutverbose
.Shouldn't pydocstyle be complaining that
skips
doesn't start on the same line, too?Personally I'd prefer pydocstyle to accept that docstrings can start on the line below a parameter instead of forcing the user to write on the same like
e.g.
This is considered valid.
This should also be considered valid.
To me, the latter feels more "right". But to be fair though, I didn't see anything in the google style guide indicating it's okay for descriptions could start one line down. So maybe you don't agree with that suggestion.
At the very least though, I'd like pydocstyle to enforce D417 consistently.
skips
should also be failing, which it isn't currently.Environment Details
Python: 3.7.3
command:
pydocstyle --ignore=D213,D202,D203,D406,D407 foo.py
pydocstyle version: 5.0.1
The text was updated successfully, but these errors were encountered: