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

Adds support to ignored-argument-names in DocstringParameterChecker #3842

Conversation

luigibertaco
Copy link
Contributor

@luigibertaco luigibertaco commented Sep 18, 2020

Steps

  • Add yourself to CONTRIBUTORS if you are a new contributor.
  • Add a ChangeLog entry describing what your PR does.
  • If it's a new feature or an important bug fix, add a What's New entry in doc/whatsnew/<current release.rst>.
  • Write a good description on what the PR does.

Description

Adds support to ignored arguments from the ignored-argument-names config such as "_", for instance.
To avoid breaking changes it also accepts ignored argument names to be documented.

Type of Changes

Type
✨ New feature

Related Issue

Closes #3800

@coveralls
Copy link

Coverage Status

Coverage increased (+0.003%) to 90.724% when pulling 781df0e on luigibertaco:enhancement-3800-ignore-argument-names-on-docstring-parmaeters into 4980369 on PyCQA:master.

@coveralls
Copy link

coveralls commented Sep 18, 2020

Coverage Status

Coverage increased (+0.009%) to 90.73% when pulling 7b70e02 on luigibertaco:enhancement-3800-ignore-argument-names-on-docstring-parmaeters into c433df7 on PyCQA:master.

@hippo91 hippo91 self-assigned this Sep 19, 2020
Copy link
Contributor

@hippo91 hippo91 left a comment

Choose a reason for hiding this comment

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

@luigibertaco thanks a lot for this improvement.
My main concern is about the fact that pylint could accept to document an unused/ignored parameter.

self, "ignored-argument-names", set()
)
if ignored_argument_names:
ignored_argument_names = {
Copy link
Contributor

Choose a reason for hiding this comment

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

It may be not a good idea to use the same name for two different types. ignored_argument_names is initially a re pattern object and then is affected to a set.
Maybe the set could be named expected_but_ignored_arg_names or something like that?

@@ -443,6 +444,16 @@ class constructor.
expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()

ignored_argument_names = get_global_option(
self, "ignored-argument-names", set()
Copy link
Contributor

Choose a reason for hiding this comment

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

If the option is retrieved then it will be a re pattern object, if it is not retrieved why not get None instead of set?

@@ -476,7 +487,7 @@ class constructor.
params_with_type,
"missing-type-doc",
not_needed_type_in_docstring,
expected_argument_names,
expected_argument_names - ignored_argument_names,
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm wondering if we should also modify the expected_argument_names in the calls to _compare_different_args?

Comment on lines +2232 to +2233
:param _: Another argument.
:type _: float
Copy link
Contributor

Choose a reason for hiding this comment

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

Does it makes sense to document an unused/ignored parameter?
IMHO i don't think so. By modifying the calls to _compare_different_args then pylint should be able to detect this and will emit differing-param-doc. Maybe we can think about changing the message in this case to something around useless-param-doc...

Copy link
Contributor Author

Choose a reason for hiding this comment

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

My main reason for this was to avoid breaking changes. But I agree with you, I haven't thought about adding a new message, that is a good idea.

@luigibertaco luigibertaco force-pushed the enhancement-3800-ignore-argument-names-on-docstring-parmaeters branch from 847b520 to 1ffeba1 Compare September 25, 2020 06:38
@luigibertaco luigibertaco force-pushed the enhancement-3800-ignore-argument-names-on-docstring-parmaeters branch from 1f867d2 to 2378dc1 Compare September 25, 2020 07:20
Copy link
Contributor

@hippo91 hippo91 left a comment

Choose a reason for hiding this comment

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

@luigibertaco thanks a lot for this great work!
I left only two suggestions and a question concerning your docstring.
After that we will be clear to merge!

Comment on lines 417 to 418
:param set found_argument_names: argument names found in the
docstring
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I'm wrong but it seems that your docstring is a mix between different ones. Usually for sphinx type docstring you put the argument type on a different line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I am with you on that, it was new for me but it is the style that is being used on the file as you can see on the existing methods: https://github.com/PyCQA/pylint/pull/3842/files/2378dc143d99e66febb1c3daeb66fbbb1b3e7d7c#diff-61228d78a7c97a0961324b4e7e6eb65eR383

I then chose to keep the same style instead of mixing them.

Happy to change for what you think would be more appropriate. What is your opinion on that?

Copy link
Contributor

Choose a reason for hiding this comment

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

@luigibertaco it seems as this style is used only in the _compare_missing_args, _compare_ignored_args and _compare_different_args methods. I suppose it is a mistake. Do you mind correcting it?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Hi @hippo91, I've fixed the sphinx style on the methods, but it got me thinking if pylint shouldn't have raised a warning for that.

"W9019": (
'"%s" useless ignored parameter documentation',
"useless-param-doc",
"Please check ignored parameter names in declarations.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Why not something more directive such as:

Please remove the ignored parameter documentation
```?

"W9020": (
'"%s" useless ignored parameter type documentation',
"useless-type-doc",
"Please check ignored parameter names in type declarations.",
Copy link
Contributor

Choose a reason for hiding this comment

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

Idem

Copy link
Contributor

@hippo91 hippo91 left a comment

Choose a reason for hiding this comment

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

Thanks a lot @luigibertaco !

@hippo91 hippo91 merged commit 9a97be4 into pylint-dev:master Oct 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Ignore special argument names on Parameter Documentation checker
3 participants