-
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
[pylint
] Add missing return doc rule (W9011
)
#8843
[pylint
] Add missing return doc rule (W9011
)
#8843
Conversation
This PR is part of astral-sh#970, it adds the `W9011` error rule.
|
Thanks for contributing!
|
Co-authored-by: Zanie Blue <contact@zanie.dev>
I looked through the ecosystem checks and most violations are true positives. Since this rule only checks for docstrings following reST, some violations are for following other documentation styles. The only case I would consider potentially problematic is that private functions are not ignored. I'm not quite sure what the best behavior would be in that case, on one hand it makes sense to document private functions too, but on the other hand, private functions are internal affairs where a bit more leeway can be given. Do you have an opinion on what would be preferable in this case? |
Unless pylint handles private functions differently, I think we can treat them the same for now. I could imagine a setting to enable or disable documentation rules for private functions in the future. |
Given the number of projects that opt-in to PLW without using reST docstrings, I'm a little worried about adding this rule. Perhaps there's a way we can shrink the scope to only effect projects using that docstring style? Maybe there's a pattern in https://github.com/astral-sh/ruff/blob/017e82911595bab746172b7976f993b715be4d79/crates/ruff_linter/src/checkers/ast/analyze/definitions.rs that we should follow? @charliermarsh may have more concrete advice or opinions. |
Turns out the pylint rule ignores private functions, so let's ignore them here as well. Regarding this only applying to reST docstrings: |
@zanieb I don't think the CI triggered on my last push (there were some issues with GitHub around that time). Can you or someone else trigger the workflow manually, or should I push an empty commit to trigger the workflow? |
@johannes-graner - I went ahead and merged in main + re-pushed :) |
CodSpeed Performance ReportMerging #8843 will not alter performanceComparing Summary
|
The pydocstyle checks have a |
That sounds reasonable. However, I think that is out of scope for this PR (and should probably be handled by someone with more contributing experience than me). Would it be reasonable to simply re-use the pydocstyle convention setting with an additional way to specify it in |
Implemented an option Should eliminate any ecosystem violations since they would have to opt-in to the rule by setting the convention. This also brings the behavior slightly closer to that of pylint, which requires an explicit flag to check docstrings. I still think the convention should be a general setting, but since that would involve deprecation of the current pydocstyle convention setting, it's out of scope here and probably should have it's own issue with discussion first. |
I opened #9043 to discuss the convention setting. Depending on whether there's quick feedback, the settings should probably be updated before this PR gets merged. Otherwise, the settings introduced here would get deprecated straight away. |
Sorry for the delay here. It looks like a global setting would be reasonable. @Mr-Pepe are you interested in working on that? We'd probably want to do it separately / before this pull request is merged. |
I'm not using Python that much anymore, so I can't really justify the effort, sorry 😔 |
Thanks for creating this PR and sorry for the long time it has taken us to move this forward. We are holding off from adding any new Pylint extension rules until #1774 . The reason for is that using pylint extension rules in pylint requires explicit opt-in. This would be different when using Ruff where the rule would automatically be enabled when you use the That means we can't accept the rule right now, even though I think the rule itself would be useful. Our goal is to have a better place for this kind of rules once #1774. I'm sorry for giving that feedback so late, and I plan to go through open issues (especially the pylint one) to flag rules ahead of time. Thank you again or taking the time to contribute to Ruff. |
Summary
This PR is part of #970, it adds the
W9011
error rule.The rule checks that a return documentation is part of the docstring for functions that return something.
Exactly how the docstring is checked depends on the setting
pylint.convention
, which can take the same values aspydocstyle.convention
(Google, NumPy, or Pep257). The Pep257 option checks for reST style docstrings.Test Plan
The example from pylint documentation is used, and extended to cover more cases.