Skip to content
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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

berkersal
Copy link

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

Type
🐛 Bug fix

Description

Refs #XXXX

Closes #XXXX

@Pierre-Sassoulas Pierre-Sassoulas added the False Negative 🦋 No message is emitted but something is wrong with the code label Dec 2, 2024
Copy link

codecov bot commented Dec 2, 2024

Codecov Report

Attention: Patch coverage is 90.90909% with 1 line in your changes missing coverage. Please review.

Project coverage is 95.80%. Comparing base (0d5439b) to head (51f61ab).
Report is 2 commits behind head on main.

Files with missing lines Patch % Lines
pylint/extensions/docparams.py 90.90% 1 Missing ⚠️
Additional details and impacted files

Impacted file tree graph

@@            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     
Files with missing lines Coverage Δ
pylint/extensions/docparams.py 99.50% <90.90%> (-0.50%) ⬇️

This comment has been minimized.

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a 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 ?

Copy link
Member

@Pierre-Sassoulas Pierre-Sassoulas left a 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) ?

@Pierre-Sassoulas
Copy link
Member

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.

@berkersal berkersal force-pushed the main branch 5 times, most recently from b794ef3 to c8d7ec9 Compare December 7, 2024 16:07
@berkersal
Copy link
Author

Sorry for a lot of pushes 😅

@berkersal
Copy link
Author

Something not related to my changes is giving an error on pre-commit checks

@Pierre-Sassoulas
Copy link
Member

Sorry about that it's going to be fixed in #10165

berkersal and others added 3 commits January 4, 2025 12:40
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
Copy link
Contributor

github-actions bot commented Jan 4, 2025

🤖 According to the primer, this change has no effect on the checked open source code. 🤖🎉

This comment was generated for commit 51f61ab

Comment on lines +343 to +345
# skip functions smaller than 'docstring-min-length'
if self._is_shorter_than_min_length(node):
return
Copy link
Member

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 ?

Copy link
Author

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 😅

Copy link
Member

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 ?)

Copy link
Author

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

Copy link
Member

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)

Copy link
Author

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

Copy link
Member

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)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
False Negative 🦋 No message is emitted but something is wrong with the code
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants