-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Implement pydoclint
#12434
Comments
I would like to enforce a certain style docstrings. I do not think it is contained in the existing rules here or in In theory this case could be covered by the full set of rules if you enable all: |
This comment has been minimized.
This comment has been minimized.
Does the Astral team have an opinion on the implementation of DOC109, DOC110, and DOC111? Separating DOC109 and DOC110 seems inconsistent with how D417 works. Seeing as DOC111 is just the inverse behaviour, my intuition is that it would make the most sense for these to be consolidated into one configurable rule. |
That config also overlaps with the strikethrough rules covered by ANN. We currently ignore ANN because we run mypy. When the function is fully typehinted, the docstring doesn't need any types, sphinx will still render the docstring including arg and return types for example. |
Does anyone know if other linting tools already implemented by ruff support the |
I really like these rules as well! However, it would be great if the rules only applied to public functions and methods as indicated by a For example, I wouldn't want to waste time adding a complete and correct docstring when the function is private and ignored by most documentation generators. def _escape(text: str) -> str:
"""Hypothetical function that does some internal business logic."""
if "&&" in text:
raise CustomError()
return text.replace(";", "\;") I believe a workaround today would be to move any private functions into a file prefixed by |
This makes sense to me. We should add a configuration option, to optionally allow/disallow the DOC rules on private functions. Unfortunatelly, I won't be able to get to this any time soon. If you're up to it, feel free to open a PR. |
I can work on that (and ignore nested functions as well). |
regarding nested functions, private functions etc, here's a nice source of configs (from interrogate, a docstring coverage tool): ignore-init-method = false
ignore-init-module = false
ignore-magic = false
ignore-semiprivate = false
ignore-private = false
ignore-property-decorators = false
ignore-module = false
ignore-nested-functions = false
ignore-nested-classes = false
ignore-setters = false
ignore-overloaded-functions = false |
And personally I'd love an |
That particular configuration is likely blocked by #5860 – we'd need a member of the Astral team to decide what level of docstring configuration they'd like and how (e.g., if the configuration would apply to a subset of docstring diagnostics, or all of them). EDIT: I should probably elaborate. The proposal to restrict docstring diagnostics based on docstring complexity (what you describe) is distinct to what I linked (which is a proposal to limited based on function complexity). However, they face overlapping design challenges, so it might make sense to link them. |
|
Pydoclint introduced DOC503 for checking exceptions a few weeks ago. It's covered by DOC501/DOC502 in Ruff (which are still in preview), but perhaps worth adding to the list in this issue as completed? |
@Apakottur Yeah, and I already raised jsh9/pydoclint#171 about it. Apparently ruff is not affected by it. |
Hi @KyleKing @augustelalande @tjkuson and @ddelange : I'm the author of pydoclint. Maybe I can share some thoughts behind why pydoclint does not support omitting private functions/methods. Suppose a linter only checks certain functions in a repo and omits other functions, we may end up with a repo with mixed docstring styles as well as some other implications. For example:
That's why I didn't design such an exception in pydoclint. That said, there are indeed ways to "be lazy" in pydoclint:
|
Hi @sbrugman , I'm the author of pydoclint. In the latest version of pydoclint (0.6.0), I added a new violation code ( More details (including caveats) are here: https://jsh9.github.io/pydoclint/style_mismatch.html The authors of Ruff are welcome to add this new code in Ruff's roadmap. |
This issue tracks the implementation of pydoclint. Following discussion in #11471 it was decided to prefer
pydoclint
overdarglint
for implementation in ruff, since they cover mostly the same ruleset, andpydoclint
is still actively developed (unlikedarglint
). This issue should then supersede #458.Rules
DOC101
Docstring contains fewer arguments than in function signatureDOC102
Docstring contains more arguments than in function signatureDOC103
Docstring arguments are different from function argumentsDOC104
Arguments are the same in the docstring and the function signature, but are in a different orderDOC105
Argument names match, but type hints do not match(covered byDOC106
The option--arg-type-hints-in-signature
isTrue
but there are no argument type hints in the signatureANN
)(covered byDOC107
The option--arg-type-hints-in-signature
isTrue
but not all args in the signature have type hintsANN
)(covered byDOC108
The option--arg-type-hints-in-signature
isFalse
but there are argument type hints in the signatureANN
)DOC109
The option--arg-type-hints-in-docstring
isTrue
but there are no type hints in the docstring arg listDOC110
The option--arg-type-hints-in-docstring
isTrue
but not all args in the docstring arg list have type hintsDOC111
The option--arg-type-hints-in-docstring
isFalse
but there are type hints in the docstring arg listDOC201
Function/method does not have a return section in docstringDOC202
Function/method has a return section in docstring, but there are no return statements or annotationsDOC203
Return type(s) in the docstring not consistent with the return annotationDOC301
__init__()
should not have a docstring; please combine it with the docstring of the classDOC302
The class docstring does not need a "Returns" section, because__init__()
cannot return anythingDOC303
The__init__()
docstring does not need a "Returns" section, because it cannot return anythingDOC304
Class docstring has an argument/parameter section; please put it in the__init__()
docstringDOC305
Class docstring has a "Raises" section; please put it in the__init__()
docstringDOC306
The class docstring does not need a "Yields" section, because__init__()
cannot yield anythingDOC307
The__init__()
docstring does not need a "Yields" section, because__init__()
cannot yield anythingDOC401
(Deprecated; this violation code no longer appears)DOC402
Function/method has "yield" statements, but the docstring does not have a "Yields" sectionDOC403
Function/method has a "Yields" section in the docstring, but there are no "yield" statements, or the return annotation is not a Generator/Iterator/IterableDOC404
The types in the docstring's Yields section and the return annotation in the signature are not consistentDOC501
Function/method has "raise" statements, but the docstring does not have a "Raises" sectionDOC502
Function/method has a "Raises" section in the docstring, but there are not "raise" statements in the bodyDOC601
Class docstring contains fewer class attributes than actual class attributesDOC602
Class docstring contains more class attributes than in actual class attributesDOC603
Class docstring attributes are different from actual class attributesDOC604
Attributes are the same in docstring and class def, but are in a different orderDOC605
Attribute names match, but type hints in these attributes do not matchStyle support
The text was updated successfully, but these errors were encountered: