-
-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Respect docstring-min-length in docparams extension #10104
base: main
Are you sure you want to change the base?
Conversation
Codecov ReportAttention: Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #10104 +/- ##
==========================================
- Coverage 95.80% 95.80% -0.01%
==========================================
Files 174 174
Lines 18976 18984 +8
==========================================
+ Hits 18180 18187 +7
- Misses 796 797 +1
|
This comment has been minimized.
This comment has been minimized.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for opening a PR ! Would you mind adding functional tests (https://github.com/pylint-dev/pylint/tree/main/tests/functional/ext/docparams) and a changelog (https://github.com/pylint-dev/pylint/tree/main/doc/whatsnew/fragments) for this please ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good thank you ! Any reasons not to create a reusable function for the new code in the doc param class (copy pasted thrice as far as I understand) ?
Don't mind the fail of the CI this is due to python/cpython#125415 in 3.13.1 we're going to be able to rebase on main once it's fixed. |
b794ef3
to
c8d7ec9
Compare
Sorry for a lot of pushes 😅 |
Something not related to my changes is giving an error on pre-commit checks |
Sorry about that it's going to be fixed in #10165 |
Even though visit_functiondef is checking for docstring-min-length, it is not enough. This commit fixes the issue by adding the same check to visit_raise, visit_return and visit_yield
🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉 This comment was generated for commit 51f61ab |
# skip functions smaller than 'docstring-min-length' | ||
if self._is_shorter_than_min_length(node): | ||
return |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure it's possible to cover this, do return nodes ever have a docstring attached ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if I understand the problem 😅
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Those two lines are not covered by tests, and it's in a visit_return
function, so I suppose it's not covered because it's impossible to ever reach this code (return node don't have docstrings, right ?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure what return node
is but there is a part in docstrings that documents what the function is returning
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Return node would be obtained from something like return 4
, once parsed you'll get an ast's Return node:
Parsing:
print(ast.dump(ast.parse('return 4')))
Resut:
Module(body=[Return(value=Constant(value=4))])
(Which then become an astroid return node in pylint, before we use the visitor pattern to do something with it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I assume the extension is deciding the return part of the docstring from -> int
part of the function definition. Then it wouldn't care about the return node
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm, would it be possible to create a functional test for it then ? (I.e. with a docstring too small and return type information that we don't need to analyse because the docstring is too small if I understood correctly)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It seems it's not covering line 345 according to codecov ? (https://app.codecov.io/gh/pylint-dev/pylint/pull/10104?src=pr&el=tree&filepath=pylint%2Fextensions%2Fdocparams.py&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=pylint-dev#61228d78a7c97a0961324b4e7e6eb65e-R345)
Even though visit_functiondef is checking for docstring-min-length, it is not enough. This commit fixes the issue by adding the same check to visit_raise, visit_return and visit_yield
If there is a better way of implementing this, please go forward. I am just providing a working fix to this problem.
Type of Changes
Description
Refs #XXXX
Closes #XXXX