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

Customize arguments-differ error messages #4422

Merged
merged 20 commits into from May 5, 2021

Conversation

ksaketou
Copy link
Contributor

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

This pull request customizes the output messages of arguments-differ error message based on different error cases (type change, name change, number of parameters etc). It aims to act as a base for the creation of a new error message, arguments-renamed.

Type of Changes

Type
✨ New feature

Related Issue

Part one of #3536

This commit changes the output messages of arguments-differ based on different error cases.
It is part one of the issue pylint-dev#3536
This commit modifies the tests of arguments-differ output messages based on different error messages.
It is part one of the issue pylint-dev#3536
This commit modifies the tests for arguments-differ output messages based on different error cases.
It is part one of the issue pylint-dev#3536
This file emited arguments-differ messages on three methods in the end of the file because
some parameters have changed name compared to the original method.
@coveralls
Copy link

coveralls commented Apr 29, 2021

Coverage Status

Coverage increased (+0.01%) to 91.696% when pulling 1ba9e1d on ksaketou:args-differ-msg into ce55bce on PyCQA:master.

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, great work ! I suggested some small changes, the main thing being we should not change the existing tests, only their outputs. They're testing some use case that were constructed from dozen of issues and we need them to not regress. We can add other tests if required for typing check, having long functional test files with duplication is not a problem at all :)

arguments-differ:41:4:ClassmethodChild.func:Number of parameters has changed in overridden 'ClassmethodChild.func' method
arguments-differ:68:4:VarargsChild.has_kwargs:Parameter 'arg' was of type 'bool' and is now of type 'int' in overridden 'VarargsChild.has_kwargs' method
arguments-differ:68:4:VarargsChild.has_kwargs:Variadics removed in overridden 'VarargsChild.has_kwargs' method
arguments-differ:71:4:VarargsChild.no_kwargs:Parameter 'args' has been renamed in overridden 'VarargsChild.no_kwargs' method
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
arguments-differ:71:4:VarargsChild.no_kwargs:Parameter 'args' has been renamed in overridden 'VarargsChild.no_kwargs' method
arguments-differ:71:4:VarargsChild.no_kwargs:Parameter 'args' has been renamed to 'arg' in overridden 'VarargsChild.no_kwargs' method

arguments-differ:68:4:VarargsChild.has_kwargs:Parameter 'arg' was of type 'bool' and is now of type 'int' in overridden 'VarargsChild.has_kwargs' method
arguments-differ:68:4:VarargsChild.has_kwargs:Variadics removed in overridden 'VarargsChild.has_kwargs' method
arguments-differ:71:4:VarargsChild.no_kwargs:Parameter 'args' has been renamed in overridden 'VarargsChild.no_kwargs' method
arguments-differ:172:4:SecondChangesArgs.test:Number of parameters has changed in overridden 'SecondChangesArgs.test' method
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
arguments-differ:172:4:SecondChangesArgs.test:Number of parameters has changed in overridden 'SecondChangesArgs.test' method
arguments-differ:172:4:SecondChangesArgs.test:Number of parameters was 4 in 'Classname.base_method' and is now 5 in overridden 'SecondChangesArgs.test'

pylint/checkers/classes.py Show resolved Hide resolved
overridden: List[astroid.AssignName],
dummy_parameter_regex: Pattern,
counter: int,
):
Copy link
Member

Choose a reason for hiding this comment

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

Here it was a boolean before it look like it's now a list of string.

Suggested change
):
) -> List[str]:

return True
return False
result.append(
"Parameter '" + str(original_param.name) + "' has been renamed in"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Parameter '" + str(original_param.name) + "' has been renamed in"
f"Parameter '{original_param.name}' has been renamed to '{overridden_param.name}' in"

original: List[astroid.FunctionDef],
overridden: List[astroid.FunctionDef],
dummy_parameter_regex: Pattern,
):
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
):
) -> List[str]:

)
if len(different_kwonly) > 0:
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
if len(different_kwonly) > 0:
if different_kwonly:

@@ -3,13 +3,13 @@

class Parent(object):

def test(self):
Copy link
Member

Choose a reason for hiding this comment

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

Could we refrain from changing the existing functional test in this MR, please ? I would like to see if the old use cases are all handled well. We can add more functional tests if required :)

@ksaketou
Copy link
Contributor Author

Thank you! Okay I see, I'm working on these changes :)

ksaketou and others added 5 commits April 30, 2021 16:43
This commit removes several changes that have been done on some method parameters,
 so that we keep the initial format of the tests.
This commit adds some changes on the output messages and also adds some more code for the
compatibility with the initial tests.
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 , great work and very nice new message ! Could we also keep the typing change in functional tests for the next MR, please?

Comment on lines 293 to 299
"Parameter '"
+ str(original_param.name)
+ "' was of type '"
+ original_type
+ "' and is now of type '"
+ overridden_type
+ "' in"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
"Parameter '"
+ str(original_param.name)
+ "' was of type '"
+ original_type
+ "' and is now of type '"
+ overridden_type
+ "' in"
f "Parameter '{original_param.name}' was of type '{original_type}' and "
"is now of type '{overridden_type}' in"

@ksaketou
Copy link
Contributor Author

ksaketou commented May 4, 2021

Thank you , great work and very nice new message ! Could we also keep the typing change in functional tests for the next MR, please?

Thank you! What do you mean exactly? The parameter types on the tests?

ChangeLog Outdated
@@ -51,6 +51,8 @@ Release date: 2021-04-25

Closes #4399

* Customize output messages for ``arguments-differ`` error message based on the different error cases.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
* Customize output messages for ``arguments-differ`` error message based on the different error cases.
* The warning for ``arguments-differ`` now signal explicitly the difference it detected by naming the argument or type that changed.

tests/functional/a/arguments_differ.py Show resolved Hide resolved
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.

It look like we're getting a problem in the pipeline because of #4439. I'll merge as soon as someone fix it and the test pass when we rebase. Thank you for all the work on this !

@ksaketou
Copy link
Contributor Author

ksaketou commented May 5, 2021

My pleasure! So I have to wait for this PR to be merged in order to start working on the second pull request?

@Pierre-Sassoulas
Copy link
Member

Well, you can disregard the error and start the second one, we will rebase on master once the first one is merged. I also see that there is a problem with mypy that you could check before that: https://results.pre-commit.ci/run/github/47671127/1620160302.btadc94JQO-yT6SZWp2aLg

@cdce8p
Copy link
Member

cdce8p commented May 5, 2021

It look like we're getting a problem in the pipeline because of #4439. I'll merge as soon as someone fix it and the test pass when we rebase. Thank you for all the work on this !

The pylint problem here isn't related to the issue you linked. AFAIK it's because the annotation was assumed to have the name attribute. However that isn't always the case. It can also be of type astroid.Attribute which only has attrname.

https://github.com/PyCQA/pylint/blob/d05d2a18b57221c464c6d0799ba40bf66f306483/pylint/checkers/classes.py#L286-L290

@ksaketou
Copy link
Contributor Author

ksaketou commented May 5, 2021

I am working on the mypy errors, I think they might fix the problem. I had a small mistake on the parameter typing here.
https://github.com/PyCQA/pylint/blob/d05d2a18b57221c464c6d0799ba40bf66f306483/pylint/checkers/classes.py#L311-L312

ksaketou and others added 2 commits May 5, 2021 21:37
This commit fixes the ignoring of special methods on function overriding and also removes incorrect use of
the attribute name.
@Pierre-Sassoulas Pierre-Sassoulas merged commit 7167442 into pylint-dev:master May 5, 2021
@ksaketou ksaketou deleted the args-differ-msg branch May 7, 2021 11:08
ksaketou added a commit to ksaketou/pylint that referenced this pull request May 11, 2021
This commits creates the new error arguments-renamed based on the functionality
added on pylint-dev#4422 and the changes of pylint-dev#4456.
@ksaketou ksaketou mentioned this pull request May 11, 2021
4 tasks
Pierre-Sassoulas added a commit that referenced this pull request May 17, 2021
* Create new error arguments-renamed

This commits creates the new error arguments-renamed based on the functionality
added on #4422 and the changes of #4456.

* Merge test files for arguments-differ

This commit merges the two kinds of test files that existed for the arguments-differ error, since now all
tests run in Python3.

* Add tests for arguments-renamed error
* Add new error arguments-renamed

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants