-
-
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
Separate functionality of arguments-differ with new error message called arguments-renamed #4347
Conversation
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.
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 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 :)
@@ -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 |
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.
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)
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 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] |
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.
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 ?
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.
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 |
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.
arg1 was renamed to param1 though ?
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.
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 |
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.
Haven't the two first arguments been renamed ? Even the type changed.
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.
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. | ||
""" |
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.
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 |
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.
Probably not related to the current MR but that would be nice to have:
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 ?
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.
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
From what I understood, the |
Hello @Pierre-Sassoulas . I am wondering how do you want me to keep working on that PR? As I mentioned, I cannot remove the |
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 |
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. |
Okay nice, I will do my best then 😀 |
Hello again, I have another question. I have written some code and now I am running all the tests with |
Did you install |
Okay it runs now, thanks 😅 |
Steps
doc/whatsnew/<current release.rst>
.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
Related Issue
Closes #3536