-
Notifications
You must be signed in to change notification settings - Fork 15
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
Add support for Google-style comments #3
Comments
Hi @leandro-lucarella-frequenz , thanks for the vote of confidence! I already found this docstring parser (https://github.com/rr-/docstring_parser) that seemed to parse Google-style docstrings well. I plan to start to integrate this parser in a few days, if not sooner. |
Hi @leandro-lucarella-frequenz , I've added support for the Google style. It's in 0.0.3. Please feel free to give it a try! I'm closing this issue as "done". But if you find any issues, bugs, or have some feature requests, please feel free to open new issues. |
Amazing, thanks! I'll try to find a time slot to try it this week! |
Actually I just gave it a quick try. We are using a style that includes documentation in the For more context, we are using mkdocs + mkdocstrings to generate the docs (for example https://frequenz-floss.github.io/frequenz-channels-python/). It does have an option to mix the the class and |
One of the current rules in pydoclint is:
I set up this rule because:
Does your team have a strong reason to put documentation in both |
As I said, there was a reason, I don't remember exactly what, but I remember trying both out and deciding for the split. I see the template you link is from Sphinx, but the official google style guide documents the I think a mechanism to ignore some rule as most linting tools have will be generally beneficial regardless of this particular issue. |
BTW, the Sphinx template you link also documents the class ExampleClass:
"""The summary line for a class docstring should fit on one line.
If the class has public attributes, they may be documented here
in an ``Attributes`` section and follow the same formatting as a
function's ``Args`` section. Alternatively, attributes may be documented
inline with the attribute's declaration (see __init__ method below).
Properties created with the ``@property`` decorator should be documented
in the property's getter method.
Attributes:
attr1 (str): Description of `attr1`.
attr2 (:obj:`int`, optional): Description of `attr2`.
"""
def __init__(self, param1, param2, param3):
"""Example of docstring on the __init__ method.
The __init__ method may be documented in either the class level
docstring, or as a docstring on the __init__ method itself.
Either form is acceptable, but the two should not be mixed. Choose one
convention to document the __init__ method and be consistent with it.
Note:
Do not include the `self` parameter in the ``Args`` section.
Args:
param1 (str): Description of `param1`.
param2 (:obj:`int`, optional): Description of `param2`. Multiple
lines are supported.
param3 (list(str)): Description of `param3`.
""" |
Thanks for providing the code example! Can you confirm that these are the desired behaviors:
The 1st point be easily achieved. The 2nd point may be a bit tricky, because it requires the following:
It's probably still doable though. |
class ExampleClass:
"""The summary line for a class docstring should fit on one line.
If the class has public attributes, they may be documented here
in an ``Attributes`` section and follow the same formatting as a
function's ``Args`` section. Alternatively, attributes may be documented
inline with the attribute's declaration (see __init__ method below).
Properties created with the ``@property`` decorator should be documented
in the property's getter method.
"""
class_variable: str = "test"
"""This is the documentation of the class variable."""
def __init__(self, param1, param2, param3):
"""Example of docstring on the __init__ method.
Args:
...
"""
self.attr1: str = param1
"""This is the documentation for the attr1 instance attribute.""" I think this is pretty non-standard, and also there isn't much to check with this way of documenting, so for our specific use case 2. is not needed at all. If I may derail a bit, speaking of attributes, one thing that is very annoying for us about darglint is also that it will check @property
def delay_tolerance(self) -> timedelta:
"""Return the maximum delay that is tolerated before starting to drift.
Returns:
The maximum delay that is tolerated before starting to drift.
"""
return timedelta(microseconds=self._tolerance) We would love to write this instead: @property
def delay_tolerance(self) -> timedelta:
"""The maximum delay that is tolerated before starting to drift."""
return timedelta(microseconds=self._tolerance) (we still would have one issue with this because we use also http://www.pydocstyle.org/en/stable/, which also requires function to start with a verb, but we didn't investigate if there is a way to escape that for properties in pydocstyle yet) |
For reference this is the darglint issue: terrencepreilly/darglint#94 |
Hi @leandro-lucarella-frequenz : I've merged #7, which added an option By default, it's As to the issue of pydoclint/pydoclint/utils/arg.py Lines 108 to 121 in 30eedbd
This is a happy coincidence. But if you for some reason need to set it to But other aspects are out of the control of
|
Hi @jsh9, first of all I want to thank you for following up on this (for so song and so deep :). I'll try About properties, this for use would be the best option:
We don't want to allow short descriptions in general, if a function has arguments we want to get lint error on functions that don't document them even if the docstring is one line.
Yeah, I hope at some point there is a way to change that in Thanks a lot again! |
OK, I just tried it out and it works like a charm with There are a few bad news though: After trying it I realized it worked without specifying the
Also trying to use PS: Using |
Let me take a look at this bug. |
Would you be able to isolate the Python file that resulted in this issue? If so, I'd be able to isolate the issue much easier. Right now it's a bit hard for me to reproduce this issue on my end. |
I found the file that triggered this issue. It's this one: https://github.com/frequenz-floss/frequenz-channels-python/blob/ef9bc4740b8e9d1d0a51b109089832a4acc4fdeb/src/frequenz/channels/_base_classes.py Let me debug it. |
I fixed the bug in this commit: 64f6250 And then I tested pydoclint on your repo (https://github.com/frequenz-floss/frequenz-channels-python) with this command:
It worked well. |
Oh, amazing, thanks for digging into this with so little info provided! I tried it with another project we have and I'm still getting the exception (or a very similar one): $ pydoclint -aid True --style=google src/
Skipping files that match this pattern: \.git|\.tox
src/conftest.py
...
src/frequenz/sdk/timeseries/_ringbuffer/serialization.py
Traceback (most recent call last):
File "/home/luca/devel/sdk/.direnv/python-3.11.2/bin/pydoclint", line 8, in <module>
sys.exit(main())
^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/click/core.py", line 1130, in __call__
return self.main(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/click/core.py", line 1055, in main
rv = self.invoke(ctx)
^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/click/core.py", line 1404, in invoke
return ctx.invoke(self.callback, **ctx.params)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/click/core.py", line 760, in invoke
return __callback(*args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/click/decorators.py", line 26, in new_func
return f(get_current_context(), *args, **kwargs)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/pydoclint/main.py", line 144, in main
violationsInAllFiles: Dict[str, List[Violation]] = _checkPaths(
^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/pydoclint/main.py", line 225, in _checkPaths
violationsInThisFile: List[Violation] = _checkFile(
^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/pydoclint/main.py", line 260, in _checkFile
visitor.visit(tree)
File "/usr/lib/python3.11/ast.py", line 418, in visit
return visitor(node)
^^^^^^^^^^^^^
File "/usr/lib/python3.11/ast.py", line 426, in generic_visit
self.visit(item)
File "/usr/lib/python3.11/ast.py", line 418, in visit
return visitor(node)
^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/pydoclint/visitor.py", line 88, in visit_FunctionDef
doc: Doc = Doc(docstring=docstring, style=self.style)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/pydoclint/utils/doc.py", line 26, in __init__
self.parsed = parser.parse(docstring)
^^^^^^^^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/docstring_parser/google.py", line 285, in parse
ret.meta.append(self._build_meta(part, title))
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "/home/luca/devel/sdk/.direnv/python-3.11.2/lib/python3.11/site-packages/docstring_parser/google.py", line 112, in _build_meta
raise ParseError(f"Expected a colon in {text!r}.")
docstring_parser.common.ParseError: Expected a colon in 'I/O related exceptions when the file cannot be written.'. This is the file triggering the issue: https://github.com/frequenz-floss/frequenz-sdk-python/blob/v0.x.x/src/frequenz/sdk/timeseries/_ringbuffer/serialization.py |
So this is a separate issue. At the end of the call stack:
This means that this part of the docstring is not written in a way that conforms to the Google-style docstring. I think it should be written like this:
That said, unparsable docstrings should not have failed the entire linter. So I'm going to make a code change to turn docstring parsing errors into a style violation. |
Ah, interesting that Thanks again for looking into it! |
Hi @leandro-lucarella-frequenz , I just published version 0.0.4. In this version, you'll see this violation:
|
Hi @leandro-lucarella-frequenz : I made a code change (#13) to address the issue that With this code change, property methods no longer need a return section in their docstrings. |
Hi @jsh9, thanks a lot for the updates! I'm still bumping into a few issues, but I think I already hijacked this issue enough, so I'm creating new issues for the other problems :) |
I know it is already planned, but I just wanted to create an issue so this has some visibility and people can also vote for it with a 👍 reaction for example.
We would love to replace the dead corpse of darglint with this tool :)
The text was updated successfully, but these errors were encountered: