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

Separate functionality of arguments-differ with new error message called arguments-renamed #4347

Closed
wants to merge 7 commits into from

Conversation

ksaketou
Copy link
Contributor

Steps

  • 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 separates the functionality of error message arguments-differ in two errors.
It creates a new error message called arguments-renamed which checks if the argument name of an overridden function has changed compared to the original, without having changed type. arguments-differ checks the type of args, **kwargs, number of args etc without including the argument names.

Type of Changes

Type
✨ New feature
📜 Docs

Related Issue

Closes #3536

This commit adds a new error message called arguments-renamed. It is raised when an overridden function's argument
has been renamed compared to the original without having changed type. The commit also removes the functionality from
arguments-differ of checking if the argument names have changed.
This commit updates the arguments-differ test by removing expected errors where only the name has changed
as this will be tracked from arguments-renamed. It also adds a few more test cases.
This commit adds the test for the arguments-renamed error message. The test checks in different cases
if the argument names of overridden functions have changed without changing type compared to the original function.
This commit adds the new error message arguments-renamed on ChangeLog. This error was created
to separate functionality of arguments-differ error message.
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 working on this ! Would it be possible to do a refactoring MR first, for the removal of dummy_parameter_regex, please ? It would make the change more reviewable :)

pylint/checkers/classes.py Outdated Show resolved Hide resolved
pylint/checkers/classes.py Outdated Show resolved Hide resolved
pylint/checkers/classes.py Show resolved Hide resolved
@@ -1,5 +1,5 @@
"""Test that we are emitting arguments-differ when the arguments are different."""
# pylint: disable=missing-docstring, too-few-public-methods, unused-argument,useless-super-delegation, useless-object-inheritance
# pylint: disable= arguments-renamed, missing-docstring, too-few-public-methods, unused-argument,useless-super-delegation, useless-object-inheritance
Copy link
Member

Choose a reason for hiding this comment

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

What is the new result of this file if we keep it the same than before? It's just to picture easily what changed in this MR :) (thinking is hard)

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 just added that so that the test emit only the argument-differ errors. I think it is less complicated and easier to understand the test output for arguments-differ.


class ChildDefaults(ParentDefaults):

def test1(self, param1: str, param2: str): # [arguments-renamed]
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
def test1(self, param1: str, param2: str): # [arguments-renamed]
def test1(self, param1: str, param2: str): # [arguments-renamed, argument-renamed]

I think the expected result is two messages. One with arg renamed to param1 and one with barg renamed to param2 in the message. What do you think ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Since the output message is "Parameters have been renamed" and not "Parameter" and also it doesn't specify the arguments, so I believe one message is enough.

def test2(self, param1: int, param2: bool, param3: int): # no arguments-renamed here
print(f"Argument values are {param1}, {param2} and {param3}!")

def test3(self, param1: bool, arg2: bool): # no arguments-renamed here
Copy link
Member

Choose a reason for hiding this comment

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

arg1 was renamed to param1 though ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yes but the type has changed, so I think it is considered arguments-differ. It would be arguments-renamed only if the name had changed and not the type

def test1(self, param1: str, param2: str): # [arguments-renamed]
print(f"Argument values are {param1} and {param2}")

def test2(self, param1: int, param2: bool, param3: int): # no arguments-renamed here
Copy link
Member

Choose a reason for hiding this comment

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

Haven't the two first arguments been renamed ? Even the type changed.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Same here, the type has changed too so I think it is considered an arguments-differ, unless I understood something wrong

# pylint: disable=arguments-differ, missing-docstring, no-self-use, too-few-public-methods, useless-object-inheritance, line-too-long
"""Test where we are emitting arguments-renamed when the
arguments have been renamed without changing type.
"""
Copy link
Member

Choose a reason for hiding this comment

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

Nice functional tests ! (although I kinda miss the fruity example 😄 )

@@ -4,3 +4,4 @@ arguments-differ:41:4:ClassmethodChild.func:Parameters differ from overridden 'f
arguments-differ:68:4:VarargsChild.has_kwargs:Parameters differ from overridden 'has_kwargs' method
arguments-differ:71:4:VarargsChild.no_kwargs:Parameters differ from overridden 'no_kwargs' method
arguments-differ:172:4:SecondChangesArgs.test:Parameters differ from overridden 'test' method
arguments-differ:239:4:ChildClass2.meth:Parameters differ from overridden 'meth' method
Copy link
Member

Choose a reason for hiding this comment

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

Probably not related to the current MR but that would be nice to have:

Suggested change
arguments-differ:239:4:ChildClass2.meth:Parameters differ from overridden 'meth' method
arguments-differ:239:4:ChildClass2.meth:Parameter 'arg' was of type 'int' in 'ParentClass' and is now a 'bool' in overridden 'ChildClass2.meth' method

Could we do something similar in argument-renamed ?

Copy link
Contributor Author

@ksaketou ksaketou Apr 14, 2021

Choose a reason for hiding this comment

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

Nice idea @Pierre-Sassoulas , but at that case I think we would have multiple cases for *args, **kwargs, argument removals, additions etc. Maybe a bit complicated? For the arguments-renamed it's more simple, maybe we could say for example :
arguments-renamed:200:4:ChildClass2.meth:Parameter 'arg' in 'ParentClass' has been renamed to 'arg1' in overridden 'ChildClass2.meth' method

@Pierre-Sassoulas Pierre-Sassoulas added Checkers Related to a checker Enhancement ✨ Improvement to a component labels Apr 13, 2021
@ksaketou
Copy link
Contributor Author

ksaketou commented Apr 14, 2021

Thank you for working on this ! Would it be possible to do a refactoring MR first, for the removal of dummy_parameter_regex, please ? It would make the change more reviewable :)

From what I understood, the dummy_parameter_regex is necessary for the current functionality of arguments-differ (before the creation of arguments-renamed), because I tried to remove it but the tests fail. On arguments-differ we dont check the type of the arguments at all and we only check the names, so I think the regex serves some kind of purpose (which I haven't fully understood).

@ksaketou
Copy link
Contributor Author

Hello @Pierre-Sassoulas . I am wondering how do you want me to keep working on that PR? As I mentioned, I cannot remove the dummy_parameter_regex from the current version of the code (without the arguments-renamed error), so I cannot create a separate pull request for that. 😢 I added the argument types on the functions as you suggested. Do you want me to create some tests for Python3 so that more tests pass?

@Pierre-Sassoulas
Copy link
Member

I think this become too huge of a change and that we'll have to separate the MR in two. The first step could be to make a better message for arguments-differ (something like : #4347 (comment)) on the numerous use cases we created here. Then the seconde step could be rebasing on it and we'd be able to check that arguments-differ stays coherent and that the new message arguments-renamed have a similar detailed message in the proper cases. What do you think ?

@ksaketou
Copy link
Contributor Author

Great, so the first pull request will change the output message for arguments-differ as you suggested, without changing its functionality, and the second pull request will be the creation of arguments-renamed , right?
Also, how will we manage the messages for arguments-differ? They cannot have only the format you suggested since this error covers many cases (change of type, less/more parameters than the original method, kwargs etc)

@Pierre-Sassoulas
Copy link
Member

Great, so the first pull request will change the output message for arguments-differ as you suggested, without changing its functionality, and the second pull request will be the creation of arguments-renamed , right?

👍

Regarding the message, I trust you to create a descriptive message for each case 😄 I think having the name of arguments that differ and what differ if it's the type is really helpful, but the exact wording is not that important.

@ksaketou
Copy link
Contributor Author

Okay nice, I will do my best then 😀

@ksaketou
Copy link
Contributor Author

Hello again, I have another question. I have written some code and now I am running all the tests with python -m pytest but the benchmark tests are failing. Does that have to do with the issue I am working on?

@Pierre-Sassoulas
Copy link
Member

Did you install pytest-benchmark ? :)

@ksaketou
Copy link
Contributor Author

Okay it runs now, thanks 😅

@ksaketou ksaketou closed this May 17, 2021
@ksaketou ksaketou deleted the issue-3536-arg-differ branch May 17, 2021 13:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Checkers Related to a checker Enhancement ✨ Improvement to a component
Projects
None yet
Development

Successfully merging this pull request may close these issues.

arguments-differ is triggered if just arg names changed
2 participants